Exemple #1
0
def get_plottag(script_path):
    """ Saves js in script_path and returns tag for embedding in html
    """
    import numpy as np
    import pandas as pd
    import os

    y_data = np.random.randn(100)
    x_data = pd.date_range('31-Aug-2014', periods=len(y_data))

    figure(x_axis_type='datetime', 
           tools='pan,wheel_zoom,box_zoom,reset,previewsave,crosshair', 
           name='test plot')
    hold()
    line(x_data, y_data,
         line_color="#D95B43", line_width=4, alpha=0.7, 
         legend='random', 
         background_fill= '#cccccc')
    circle(x_data, y_data, 
           color='red', fill_color=None, size=6, 
           legend='random')
    curplot().title = 'Test Plot'
    xaxis().axis_label='date'
    yaxis().axis_label='some random numbers'
    grid().grid_line_color='white'
    grid().grid_line_alpha = 0.5

    plotid = curplot()._id
    script_path = os.path.join(script_path, plotid+'.js')
    js, tag = autoload_static(curplot(), CDN, script_path=script_path)
    with open(script_path, 'w') as f:
        f.write(js)
        
    return tag
Exemple #2
0
def build_timeplot(data):
    output_file('distribution.html', title='distribution')#, js="relative", css="relative")
    x,y=[],[]
    if len(data)>0:
        x,y=zip(*[(k, data[k]) for k in sorted(data)])
    line([pd.DatetimeIndex([dt])[0] for dt in x] , [int(yt) for yt in y],x_axis_type='datetime', tools="pan,zoom,resize", width=400,height=300, title = 'voorkomens')  
    xaxis()[0].axis_label = "Datum"
    yaxis()[0].axis_label = "# artikels"
    # Create an HTML snippet of our plot.
    snippet = curplot().create_html_snippet(embed_base_url='/static/plots/', embed_save_loc=plotdir)
    # Return the snippet we want to place in our page.
    return snippet
Exemple #3
0
    def draw(self, x, y, z, title, func, **kwargs):
        import bokeh.plotting as bk
        #TODO: change colors if y is of list type
        y = (y if type(y) == list else [y]) # wrap y to a list so that we can iterate

        kwargs.update({ "outline_line_color":"black", #FIXME refactor
                        "plot_width":300,
                        "plot_height":300,
                      })
        bk.hold(True)
        for yi in y:
            x_data, y_data = self[x], self[yi]
            func(x=x_data,
                 y=y_data,
                 title=title,
                 **kwargs)
        bk.hold(False)
        ret = bk.curplot()

        def _label(axis, field):
           label = kwargs.get(axis + '_label', False)
           if label:
               self.properties.plot_properties.insert(field, {axis + '_label':label})
           else:
               label = self.properties.plot_properties.select(field, axis + '_label', "None")
           return label

        def _range(axis, field):
           from bokeh.objects import Range1d
           p_range_args = kwargs.get(axis + '_range', False)
           if p_range_args:
               self.properties.plot_properties.insert(field, {axis + '_range': p_range})
           else:
               p_range = self.properties.plot_properties.select(field, axis + '_range')
           if not p_range:
                return False
           else:
                return Range1d(start=p_range[0], end=p_range[1])


        bk.xaxis().axis_label = _label('x', x)
        if _range('x', x):
            ret.x_range = _range('x', x)
        bk.yaxis().axis_label = _label('y', y[0]) #TODO can this make sense for multiplots?
        if _range('y', y[0]):
            ret.y_range = _range('y', y[0])
        return ret
def create_histogram(releases):

    number_of_bidders_list = []
    frequency_list = []
    for number_of_bidders, corresponding_releases in get_releases_by_amount_of_bidders(releases).items():
        number_of_bidders_list.append(number_of_bidders)
        frequency_list.append(len(corresponding_releases))

    zeros = [0]*len(frequency_list)
    right = [x+1 for x in number_of_bidders_list]
    histogram = quad(top=frequency_list, bottom=zeros, left=number_of_bidders_list, right=right)

    histogram.title = "Frequency of releases vs. Number of Bidders"
    xaxis()[0].axis_label = "Number of Bidders"
    yaxis()[0].axis_label = "Frequency of Releases"

    show()
Exemple #5
0
def bokeh_kin(kin_env, m_signal, color='#DF4949', alpha=1.0, **kwargs):

    m_vector = tools.to_vector(m_signal, kin_env.m_channels)
    s_signal = kin_env._multiarm.forward_kin(m_vector)

    xs, ys = [0.0], [0.0]
    for i in range(kin_env.cfg.dim):
        xs.append(s_signal['x{}'.format(i + 1)])
        ys.append(s_signal['y{}'.format(i + 1)])
    xs, ys = ys, xs  # we swap x and y for a more symmetrical look

    if isinstance(kin_env.cfg.lengths, numbers.Real):
        total_length = kin_env.cfg.lengths * kin_env.cfg.dim
    else:
        total_length = sum(kin_env.cfg.lengths)
    total_length += 0.0

    kwargs = {
        'plot_height': int(350 * 1.60),
        'plot_width': int(350 * 1.60),
        'x_range': [-1.0, 1.0],
        'y_range': [-1.0, 1.0],
        'line_color': color,
        'line_alpha': alpha,
        'fill_color': color,
        'fill_alpha': alpha,
        'title': ''
    }

    plotting.hold()
    plotting.line(xs, ys, **kwargs)
    plotting.grid().grid_line_color = None
    plotting.xaxis().major_tick_in = 0
    plotting.ygrid().grid_line_color = None
    plotting.yaxis().major_tick_in = 0

    plotting.circle(xs[:1], ys[:1], radius=0.015, **kwargs)
    plotting.circle(xs[1:-1], ys[1:-1], radius=0.008, **kwargs)
    plotting.circle(xs[-1:], ys[-1:], radius=0.01, color='red')
    plotting.hold(False)
Exemple #6
0
def bokeh_kin(kin_env, m_signal, color='#DF4949', alpha=1.0, **kwargs):

    m_vector = tools.to_vector(m_signal, kin_env.m_channels)
    s_signal = kin_env._multiarm.forward_kin(m_vector)

    xs, ys = [0.0], [0.0]
    for i in range(kin_env.cfg.dim):
        xs.append(s_signal['x{}'.format(i+1)])
        ys.append(s_signal['y{}'.format(i+1)])
    xs, ys = ys, xs # we swap x and y for a more symmetrical look

    if isinstance(kin_env.cfg.lengths, numbers.Real):
        total_length = kin_env.cfg.lengths*kin_env.cfg.dim
    else:
        total_length = sum(kin_env.cfg.lengths)
    total_length += 0.0

    kwargs ={'plot_height' : int(350*1.60),
             'plot_width'  : int(350*1.60),
             'x_range'     : [-1.0, 1.0],
             'y_range'     : [-1.0, 1.0],
             'line_color'  : color,
             'line_alpha'  : alpha,
             'fill_color'  : color,
             'fill_alpha'  : alpha,
             'title':''
            }

    plotting.hold()
    plotting.line(xs, ys, **kwargs)
    plotting.grid().grid_line_color = None
    plotting.xaxis().major_tick_in   = 0
    plotting.ygrid().grid_line_color = None
    plotting.yaxis().major_tick_in   = 0

    plotting.circle(xs[  : 1], ys[  : 1], radius=0.015, **kwargs)
    plotting.circle(xs[ 1:-1], ys[ 1:-1], radius=0.008, **kwargs)
    plotting.circle(xs[-1:  ], ys[-1:  ], radius=0.01, color='red')
    plotting.hold(False)
def create_scatter_plot(releases):

    number_of_bidders = []
    delta_time = []

    for release in releases:
        start = get_start_date(release)
        award = get_award_date(release)
        delta = get_difference_in_days(start, award)

        delta_time.append(delta)
        number_of_bidders.append(get_number_of_bidders(release))

    scatter_plot = scatter(delta_time, number_of_bidders,
                           fill_alpha=0.2, size=10,
                           name="period between start of tender period and award date vs amount of bidders")

    scatter_plot.title = "period vs. bidders"
    xaxis()[0].axis_label = "Days"
    yaxis()[0].axis_label = "Number of Bidders"

    show()
Exemple #8
0
    def test_yaxis(self):
        plt.figure()
        p = plt.circle([1,2,3], [1,2,3])
        self.assertEqual(len(plt.yaxis()), 1)

        expected = set(plt.yaxis())

        ax = LinearAxis()
        expected.add(ax)
        p.right.append(ax)
        self.assertEqual(set(plt.yaxis()), expected)

        ax2 = LinearAxis()
        expected.add(ax2)
        p.right.append(ax2)
        self.assertEqual(set(plt.yaxis()), expected)

        p.above.append(LinearAxis())
        self.assertEqual(set(plt.yaxis()), expected)

        p.below.append(LinearAxis())
        self.assertEqual(set(plt.yaxis()), expected)
Exemple #9
0
    def test_yaxis(self):
        plt.figure()
        p = plt.circle([1,2,3], [1,2,3])
        self.assertEqual(len(plt.yaxis()), 1)

        expected = set(plt.yaxis())

        ax = LinearAxis()
        expected.add(ax)
        p.right.append(ax)
        self.assertEqual(set(plt.yaxis()), expected)

        ax2 = LinearAxis()
        expected.add(ax2)
        p.right.append(ax2)
        self.assertEqual(set(plt.yaxis()), expected)

        p.above.append(LinearAxis())
        self.assertEqual(set(plt.yaxis()), expected)

        p.below.append(LinearAxis())
        self.assertEqual(set(plt.yaxis()), expected)
Exemple #10
0
import numpy as np
import bokeh.plotting as bk
from bokeh.objects import Glyph
import time

t = 0
time_x = np.array([0])
pres_y = np.array([20])

bk.output_server('Pressure')

bk.line(time_x, pres_y, color='#0000FF',
        tools='pan,wheel_zoom,box_zoom,reset,resize,crosshair,select,previewsave,embed',
        width=1200,height=300)
bk.xaxis()[0].axis_label = 'Time'
bk.yaxis()[0].axis_label = 'Pressure'

renderer = [r for r in bk.curplot().renderers if isinstance(r, Glyph)][0]
ds = renderer.data_source

while True:
    ds.data["x"] = time_x
    ds.data["y"] = pres_y
    ds._dirty = True
    bk.session().store_obj(ds)

    time.sleep(1)

    t = t + 1
    time_x = np.append(time_x,
                       time_x[t-1]+1)
Exemple #11
0
def plotting_axis():
    plotting.xaxis().minor_tick_line_color = None
    plotting.xaxis().major_tick_in = 0
    plotting.yaxis().minor_tick_line_color = None
    plotting.yaxis().major_tick_in = 0
Exemple #12
0
def plotting_axis():
    plotting.xaxis().minor_tick_line_color = None
    plotting.xaxis().major_tick_in = 0
    plotting.yaxis().minor_tick_line_color = None
    plotting.yaxis().major_tick_in = 0
Exemple #13
0
#      text(x, y, text=inds, alpha=0.5, text_font_size="5pt", text_baseline="middle", text_align="center", angle=0)

      ### find hover tool, and tell it what to look for
      hover = [t for t in bplt.curplot().tools if isinstance(t, HoverTool)][0]
      hover.tooltips = OrderedDict([ 
                                    #("index", "$index"), 
                                    ("(x,y)", "($x, $y)"),
                                    ("stefilename", "@stefilename"),
                                    ("Nmodes","@Nmodes"),
                                    ("Ntriples","@Ntriples"),
                                    ("Ngens","@Ngens"),
                                   ])

      ### label axes
      bplt.xaxis().axis_label=xlabel
      bplt.yaxis().axis_label=ylabel
      

#  bplt.show() 

#=================================================
if opts.special_plots:

  axes_loc = [0.15,0.15,0.6,0.8]
  cb_loc = [0.8, 0.15, 0.05, 0.8]

  ### Ng1 vs Ng2
  if opts.verbose: print "Ng1 vs Ng2"

  Ng1 = []
  Ng2 = []
Exemple #14
0
    cfg.lengths = 1/cfg.dim
    cfg.full_sensors = True
    kin_env = Environment.create(cfg)

    # Arm with decreasing lenghts segments
    cfg2 = cfg._deepcopy()
    cfg2.lengths = np.array([0.9**i for i in range(cfg2.dim)])
    #cfg2.lengths = np.array([random.random() for i in range(cfg2.dim)])
    cfg2.lengths = cfg2.lengths/sum(cfg2.lengths)
    kin_env2 = Environment.create(cfg2)

    m_signals = [{'j0': -31.23, 'j1': -44.21, 'j2': -20.18, 'j3': +31.55, 'j4': +35.66, 'j5':  +5.19, 'j6': +17.34, 'j7': +24.51, 'j8':  -2.69, 'j9': +26.52, 'j10': -34.87, 'j11': +10.72, 'j12': -19.38, 'j13': -33.49, 'j14': +13.78, 'j15': -22.43, 'j16': +33.61, 'j17': -28.95, 'j18': +34.31, 'j19':   45.75},
                 {'j0': -53.66, 'j1': -56.20, 'j2': -56.67, 'j3': -34.83, 'j4': -20.29, 'j5':  +7.51, 'j6': +20.92, 'j7': +25.51, 'j8': -17.59, 'j9':  +6.51, 'j10':  -9.65, 'j11': +45.70, 'j12': +20.88, 'j13': +24.25, 'j14': +28.65, 'j15': -42.79, 'j16': +34.45, 'j17': -39.90, 'j18':  +2.74, 'j19':  -11.12},
                 {'j0': +58.13, 'j1': +45.43, 'j2': -21.01, 'j3':  +2.35, 'j4': -38.90, 'j5': -39.23, 'j6': +45.14, 'j7': -57.58, 'j8': +39.49, 'j9': +29.01, 'j10':  -0.09, 'j11': -56.19, 'j12': +56.07, 'j13':  +5.91, 'j14': +36.61, 'j15': -52.65, 'j16': -58.60, 'j17': +32.45, 'j18': +43.69, 'j19': -120.77},
                 {'j0': +53.09, 'j1': +55.83, 'j2': -51.08, 'j3': +41.44, 'j4': +44.43, 'j5':  +4.67, 'j6':  +2.15, 'j7': +37.23, 'j8':  -3.77, 'j9': -46.70, 'j10': +56.41, 'j11': -21.08, 'j12': +13.73, 'j13': +47.23, 'j14':  +7.94, 'j15': -27.26, 'j16': +56.54, 'j17':  -7.77, 'j18': -18.98, 'j19': +149.46}]

    plotting.output_file('arm_vizu.html')

    for i, m_signal in enumerate(m_signals):
        bokeh_kin(kin_env, m_signal, alpha=0.2 + i*0.15)
        plotting.hold(True)
        bokeh_kin(kin_env2, m_signal, color='#91C46C', alpha=0.2 + i*0.15)
        plotting.hold(True)

    plotting.xaxis().minor_tick_line_color = None
    plotting.xaxis().major_tick_in = 0
    plotting.yaxis().minor_tick_line_color = None
    plotting.yaxis().major_tick_in = 0

    plotting.show()
Exemple #15
0
t = 0
time_x = np.array([0])
pres_y = np.array([20])

bk.output_server('Pressure')

bk.line(
    time_x,
    pres_y,
    color='#0000FF',
    tools=
    'pan,wheel_zoom,box_zoom,reset,resize,crosshair,select,previewsave,embed',
    width=1200,
    height=300)
bk.xaxis()[0].axis_label = 'Time'
bk.yaxis()[0].axis_label = 'Pressure'

renderer = [r for r in bk.curplot().renderers if isinstance(r, Glyph)][0]
ds = renderer.data_source

while True:
    ds.data["x"] = time_x
    ds.data["y"] = pres_y
    ds._dirty = True
    bk.session().store_obj(ds)

    time.sleep(1)

    t = t + 1
    time_x = np.append(time_x, time_x[t - 1] + 1)
    pres_y = np.append(