Plots

Sorted Titanic fare prices

from lvr import Lvr
from lvr.data import titanic_fares
from pygal import Line

tf = Lvr(titanic_fares())
line_chart = Line()
line_chart.show_legend = False
line_chart.show_x_labels = False

tf_rsh = tf.running_share(descending=True)
line_chart.x_labels = map(lambda x: str(x), range(len(tf_rsh)))
line_chart.add('Lvr', list(map(lambda x: x['effect'], tf_rsh)))
line_chart.render()

Effect/cause relations of Titanic fares

from lvr.data import titanic_fares
from lvr import Lvr
from math import exp, log2
from pygal import Line

tf = Lvr(titanic_fares())
levers = list(map(lambda x: x['cueff']/x['cucau'],
                  tf.running_share(descending=True)))
l = Line()
l.x_labels = map(str, range(len(levers)))
l.show_x_labels = False
l.show_legend = False
l.add('lever', levers)
l.render()

Absolute Concentration (Auerbach’s Law)

from lvr import Lvr
from lvr.data import titanic_fares
from pygal import Line
import numpy as np
from scipy import signal

tf = Lvr(titanic_fares())
tf_rsh = tf.running_share(descending=True)
abs_conc = list(map(lambda x: x[0]*x[1]['effect'], enumerate(tf_rsh, 1)))
x = list(map(lambda x: x[0], enumerate(tf_rsh, 1)))
z = np.polyfit(x, abs_conc, 3)
the_func = np.poly1d(z)
computed = list(map(lambda y: the_func(y), x))
peak = signal.find_peaks_cwt(computed, np.arange(1, len(titanic_fares())))

line_chart = Line()
line_chart.show_legend = False
line_chart.show_x_labels = True
line_chart.x_labels = map(lambda x: str(x), range(len(tf_rsh)))
line_chart.add('abs. Konz.', abs_conc)
line_chart.add('computed', computed)
line_chart.render()

Cumulative Titanic fare prices

from lvr import Lvr
from lvr.data import titanic_fares
from pygal import StackedLine

tf = Lvr(titanic_fares())
line_chart = StackedLine(fill=True)
line_chart.show_legend = False
tf_tbl = sorted(tf.tbl().items(), key=lambda x: x[0])
line_chart.x_labels = map(lambda x: str(x[0]), tf_tbl)
line_chart.add('Lvr', list(map(lambda x: x[1], tf_tbl)))
line_chart.render()

Treemap of Titanic fares

from lvr.data import titanic_fares
from lvr import Lvr, Selector
from pygal import Treemap

values = titanic_fares()
s = Selector(effects=0.5)
ef = Lvr(values)
indices = ef.indices(s)
tm = Treemap()
lngth = len(values)
tm.add('{} of {}'.format(len(indices), lngth),
       [value for index, value in enumerate(values) if index in indices])
tm.add('{} of {}'.format(len(values)-len(indices), lngth),
   [value for index, value in enumerate(values) if index not in indices])
tm.render()