コード例 #1
0
    def plot_label(self, fig):
        # only plot once!
        # use ColumnDataSource updates to change the plot
        # no re-plotting necessary!


        # plot point load
        point_load_glyph = Arrow(end=OpenHead(line_color=color_arrow,line_width=2, size=5), 
                        x_start='xS', x_end='xE', y_start='yS', y_end='yE',
                        line_width='lW', line_color='lC', source=self.point_load_source)
        fig.add_layout(point_load_glyph)

        # plot loads that use patches
        fig.patch(x='x', y='y', fill_alpha=0.5, source=self.constant_load_source)
        fig.patch(x='x', y='y', fill_alpha=0.5, source=self.triangular_load_source)
        fig.patches(xs='x', ys='y', color='c', fill_alpha=0.5, source=self.temperature_load_source)

        # plot the labels for the corresponding load
        labels = LabelSet(x='x', y='y', text='name', level='glyph', render_mode='canvas', source=self.load_labels)
        fig.add_layout(labels)

        # add force arrows into the patches
        arrow_glyphs = Arrow(end=OpenHead(line_color=color_arrow,line_width=2, size=5), 
                x_start='xS', x_end='xE', y_start='yS', y_end='yE',
                line_width='lW', line_color='lC', source=self.arrow_source)
        fig.add_layout(arrow_glyphs)
コード例 #2
0
ファイル: test_arrow.py プロジェクト: quasiben/bokeh
def test_arrow(output_file_url, selenium, screenshot):

    # Have to specify x/y range as labels aren't included in the plot area solver
    plot = figure(height=HEIGHT, width=WIDTH, x_range=(0,10), y_range=(0,10), tools='')

    arrow1 = Arrow(x_start=1, y_start=3, x_end=6, y_end=8,
                   line_color='green', line_alpha=0.7,
                   line_dash='8 4', line_width=5, end=OpenHead()
                   )
    arrow1.end.line_width=8

    arrow2 = Arrow(x_start=2, y_start=2, x_end=7, y_end=7,
                   start=NormalHead(), end=VeeHead()
                   )
    arrow2.start.fill_color = 'indigo'
    arrow2.end.fill_color = 'orange'
    arrow2.end.size = 50

    plot.add_layout(arrow1)
    plot.add_layout(arrow2)

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)

    # Take screenshot
    assert screenshot.is_valid()
コード例 #3
0
ファイル: maps.py プロジェクト: vikrant327/fast-trips
def map_demand(demand, network):

    demand_xy_df, agg_demand_df, agg_od_df, taz_df = prepare_demand(
        network, demand)

    o_trip_count_df = demand_xy_df.groupby(
        ['o_taz']).size().reset_index(name='o_trips')
    d_trip_count_df = demand_xy_df.groupby(
        ['d_taz']).size().reset_index(name='d_trips')

    p_map = figure(x_axis_type="mercator",
                   y_axis_type="mercator",
                   title="Origin and Destinations for Transit Trips",
                   width=800)
    p_map.grid.visible = False
    p_map.add_tile(STAMEN_TONER)

    source = ColumnDataSource(
        data=dict(x=list(agg_demand_df['taz-lon']),
                  y=list(agg_demand_df['taz-lat']),
                  origins=list(agg_demand_df['origins']),
                  destinations=list(agg_demand_df['destinations'])))

    p_map.circle(x='x',
                 y='y',
                 source=source,
                 size="origins",
                 legend="origin",
                 fill_color="green",
                 line_color="green",
                 fill_alpha=0.15,
                 line_alpha=0.15)

    p_map.circle(x='x',
                 y='y',
                 source=source,
                 size="destinations",
                 legend="destination",
                 fill_color="navy",
                 line_color="blue",
                 line_width=4,
                 fill_alpha=0.01,
                 line_alpha=0.2)

    for index, row in agg_od_df.iterrows():
        x1 = row['o-lon']
        x2 = row['d-lon']
        y1 = row['o-lat']
        y2 = row['d-lat']

        p_map.line([x1, x2], [y1, y2], line_width=row['trips'], line_alpha=0.2)
        p_map.add_layout(
            Arrow(end=OpenHead(size=row['trips']),
                  line_color="navy",
                  line_alpha=0.2,
                  x_start=x1,
                  y_start=y1,
                  x_end=x2,
                  y_end=y2))
    return p_map
コード例 #4
0
def complex_notations_plot(*args):
    zs = np.array(args)
    m = max(np.max(np.real(np.abs(zs))), np.max(np.imag(np.abs(zs)))) + 1

    fig1 = figure(title="Complex Plane (Rectangular)",
                  plot_height=400,
                  plot_width=400,
                  x_range=[-m, m],
                  y_range=[-m, m],
                  toolbar_location=None)

    bokeh_central_axis(fig1, axis='both')
    bokeh_major_ticks(fig1)
    bokeh_hide_border(fig1)

    fig2 = figure(title="Complex Plane (Polar)",
                  plot_height=400,
                  plot_width=400,
                  x_range=[-m, m],
                  y_range=[-m, m],
                  toolbar_location=None)

    bokeh_central_axis(fig2, axis='both')
    bokeh_no_ticks(fig2)
    bokeh_hide_border(fig2)
    bokeh_hide_grid(fig2)

    for z in zs:
        c = 'green'
        z1_arrow = Arrow(x_start=0,
                         y_start=0,
                         x_end=np.real(z),
                         y_end=np.imag(z),
                         end=OpenHead(size=9, line_color=c),
                         line_color=c)
        z2_arrow = Arrow(x_start=0,
                         y_start=0,
                         x_end=np.real(z),
                         y_end=np.imag(z),
                         end=OpenHead(size=9, line_color=c),
                         line_color=c)
        fig1.add_layout(z1_arrow)
        fig2.add_layout(z2_arrow)

    show(row(fig1, fig2))
コード例 #5
0
def getWindCircle(circle_radius, dirList):
    radial_fig = figure(title="Wind Direction",
                        plot_width=500,
                        plot_height=500,
                        x_range=(-40, 40),
                        y_range=(-40, 40))
    radial_fig.circle(0,
                      0,
                      radius=circle_radius,
                      fill_color='#F4F6F6',
                      line_color='black')
    # add the smaller circles
    x_cir_ang, y_cir_ang = getAngularPoints(
        np.array(np.zeros(len(dirList), )) + circle_radius, dirList)
    radial_fig.circle(x=x_cir_ang, y=y_cir_ang, size=4, fill_color='black')
    # add wind annotations
    disp_wind = np.array([0, 60, 120, 180, 240, 300])
    x_cir_label_ang, y_cir_label_ang = getAngularPoints(
        np.array(np.zeros(len(disp_wind), )) + circle_radius + 1, disp_wind)
    cir_label_source = ColumnDataSource(
        data=dict(x=x_cir_label_ang, y=y_cir_label_ang, text=disp_wind))
    circle_labels = LabelSet(x='x',
                             y='y',
                             text='text',
                             level='glyph',
                             x_offset=0,
                             y_offset=0,
                             render_mode='canvas',
                             text_font_size='10pt',
                             source=cir_label_source)
    circle_title = Label(x=-6,
                         y=-1,
                         text='Wind Direction',
                         render_mode='canvas',
                         text_font_size='10pt',
                         text_font='helvetica',
                         text_font_style='bold')
    radial_fig.add_layout(circle_labels)
    true_north = Label(x=-0.5,
                       y=8,
                       text='N',
                       render_mode='canvas',
                       text_font_size='10pt',
                       text_font='helvetica',
                       text_font_style='bold')
    radial_fig.add_layout(
        Arrow(end=OpenHead(line_color="navy", line_width=2, size=10),
              x_start=0,
              y_start=-7.5,
              x_end=0,
              y_end=7.5,
              line_color='navy',
              line_width=2))
    radial_fig.add_layout(true_north)
    radial_fig.add_layout(circle_title)
    radial_fig.axis.visible = False
    return radial_fig
コード例 #6
0
def addArrows():
    global arrows
    edge_dispare=15
    leftArrows=[Arrow(end=OpenHead(line_color="red", line_width=1,size=4),
                   x_start=-60, x_end=-30, y_start=-edge_dispare, y_end=-edge_dispare),Arrow(end=OpenHead(line_color="red", line_width=1,size=4),
                   x_start=-40, x_end=-40,y_start=-edge_dispare,  y_end=-2*edge_dispare)]
    topArrows=[Arrow(end=OpenHead(line_color="red", line_width=1,size=4),
                   x_start=-edge_dispare, x_end=-edge_dispare,y_start=60,  y_end=30),Arrow(end=OpenHead(line_color="red", line_width=1,size=4),
                   x_start=-edge_dispare, x_end=-2*edge_dispare,y_start=40,  y_end=40)]
    rightArrows=[Arrow(end=OpenHead(line_color="red", line_width=1,size=4),
                   x_start=60, x_end=30,y_start=edge_dispare,  y_end=edge_dispare),Arrow(end=OpenHead(line_color="red", line_width=1,size=4),
                   x_start=40, x_end=40,y_start=edge_dispare,  y_end=2*edge_dispare)]
    bottomArrows=[Arrow(end=OpenHead(line_color="red", line_width=1,size=4),
                   x_start=edge_dispare, x_end=edge_dispare,y_start=-60,  y_end=-30),Arrow(end=OpenHead(line_color="red", line_width=1,size=4),
                   x_start=edge_dispare, x_end=2*edge_dispare,y_start=-40,  y_end=-40)]
    arrows={"leftArrows":leftArrows,"topArrows":topArrows,"rightArrows":rightArrows,"bottomArrows":bottomArrows}
    for key in arrows.keys():
        plot.add_layout(arrows[key][0]) # szczalka prosto
        plot.add_layout(arrows[key][1]) # szczalka w prawo
コード例 #7
0
 def __init__(self):
     # save original shape of car in a shape (to make displacement easy)
     self.carshape = SD_Shape(
         [-3, 0, 0, -0.05, -0.5, -1, -2, -2, -3],
         [0.25, 0.25, 0.7, 0.75, 0.75, 1.25, 1.25, 0.75, 0.75])
     # create column data sources for the car and its acceleration
     self.car = ColumnDataSource(
         data=dict(x=self.carshape.x, y=self.carshape.y))
     self.wheels = ColumnDataSource(data=dict(
         x=[-2.25, -0.75], y=[0.25, 0.25], w=[0.5, 0.5], h=[0.5, 0.5]))
     self.arrow = ColumnDataSource(data=dict(xS=[], yS=[], xE=[], yE=[]))
     self.v_label = ColumnDataSource(data=dict(x=[], y=[], S=[]))
     # create the figure
     self.fig = figure(tools="",
                       x_range=(-4, 31),
                       y_range=(0, 4),
                       height=100)
     #  remove graph lines
     self.fig.yaxis.visible = False
     self.fig.grid.visible = False
     self.fig.toolbar.logo = None
     self.fig.outline_line_color = None
     # draw the house
     self.fig.line([30.0, 30.0, 29.5, 30.5], [0, 3.0, 3.0, 4.0],
                   line_color="black",
                   line_width=4)
     # add the car chassis to the image
     self.fig.patch(x='x', y='y', color="#0065BD", source=self.car)
     # add the car wheels to the image
     self.fig.ellipse(x='x',
                      y='y',
                      width='w',
                      height='h',
                      source=self.wheels,
                      color="#0065BD")
     # create and add the arrow representing the velocity to the diagram
     arrow_glyph = Arrow(end=OpenHead(line_color="#003359",
                                      line_width=2,
                                      size=10),
                         x_start='xS',
                         y_start='yS',
                         x_end='xE',
                         y_end='yE',
                         source=self.arrow,
                         line_color="#003359",
                         line_width=2)
     self.fig.add_layout(arrow_glyph)
     # create the label for the velocity and add it to the diagram
     v_glyph = LabelSet(x='x',
                        y='y',
                        text='S',
                        text_color='#003359',
                        level='glyph',
                        source=self.v_label)
     self.fig.add_layout(v_glyph)
コード例 #8
0
def bokeh_scatter_plot_xy_words(df_words,
                                title='',
                                xlabel='',
                                ylabel='',
                                line_data=False,
                                filename=None,
                                default_color='blue',
                                plot_width=700,
                                plot_height=600):

    plot = bp.figure(plot_width=plot_width,
                     plot_height=plot_height,
                     title=title,
                     tools=TOOLS,
                     toolbar_location="above"
                     )  #, x_axis_type=None, y_axis_type=None, min_border=1)

    color = 'color' if 'color' in df_words.columns else default_color

    plot.scatter(x='x', y='y', size=8, source=df_words, alpha=0.5, color=color)

    plot.xaxis[0].axis_label = xlabel
    plot.yaxis[0].axis_label = ylabel

    source = ColumnDataSource(df_words)
    labels = LabelSet(x='x',
                      y='y',
                      text='words',
                      level='glyph',
                      text_font_size="9pt",
                      x_offset=5,
                      y_offset=5,
                      source=source,
                      render_mode='canvas')

    hover = plot.select(dict(type=HoverTool))
    hover.tooltips = {"word": "@words"}

    if line_data is True:
        end_arrow = OpenHead(line_color="firebrick", line_width=1, size=10)
        for i in range(1, len(df_words.index), 2):
            x_start, y_start = df_words.iloc[i - 1]['x'], df_words.iloc[i -
                                                                        1]['y']
            x_end, y_end = df_words.iloc[i]['x'], df_words.iloc[i]['y']
            plot.add_layout(
                Arrow(end=end_arrow,
                      x_start=x_start,
                      y_start=y_start,
                      x_end=x_end,
                      y_end=y_end))

    plot.add_layout(labels)
    return plot
コード例 #9
0
def plot_stream_arrow(plot,
                      line_color,
                      stream_arrow_temp,
                      temp_label_font_size,
                      x_start,
                      x_end,
                      y_start,
                      y_end,
                      stream_name=None):
    """Plot a stream arrow for the heat exchanger network diagram.

        Args:
            plot: bokeh.plotting.plotting.figure instance.
            line_color: color of arrow (defaults to white).
            stream_arrow_temp: Tempreature of the stream to be plotted.
            temp_label_font_size: font-size of the temperature label to be added.
            x_start: x-axis coordinate of arrow base.
            x_end: x-axis coordinate of arrow head.
            y_start: y-axis coordinate of arrow base.
            y_end: y-axis coordinate of arrow head.
            stream_name: Name of the stream to add as a label to arrow (defaults to None).

        Returns:
            modified bokeh.plotting.plotting.figure instance with stream arrow added.
        
        Raises:
            None            
    """
    plot.add_layout(
        Arrow(line_color=line_color,
              end=OpenHead(line_color=line_color, line_width=2, size=10),
              x_start=x_start,
              y_start=y_start,
              x_end=x_end,
              y_end=y_end))

    temp_end_label = Label(x=x_end,
                           y=y_end,
                           x_offset=-20,
                           y_offset=8,
                           text_font_size=temp_label_font_size,
                           text=str(stream_arrow_temp))
    plot.add_layout(temp_end_label)

    if stream_name:
        stream_name_label = Label(x=x_end,
                                  y=y_end,
                                  x_offset=-10,
                                  y_offset=-12,
                                  text_font_size=temp_label_font_size,
                                  text=stream_name)
        plot.add_layout(stream_name_label)
    return plot
コード例 #10
0
def bokeh_scatter_plot_xy_words2(df_words,
                                 title='',
                                 xlabel='',
                                 ylabel='',
                                 line_data=False):

    plot = bp.figure(plot_width=700,
                     plot_height=600,
                     title=title,
                     tools="pan,wheel_zoom,box_zoom,reset,hover,previewsave",
                     toolbar_location="above"
                     )  #, x_axis_type=None, y_axis_type=None, min_border=1)

    # plotting. the corresponding word appears when you hover on the data point.
    plot.scatter(x='x', y='y', size=8, source=df_words, alpha=0.5)
    plot.xaxis[0].axis_label = xlabel
    plot.yaxis[0].axis_label = ylabel

    source = ColumnDataSource(df_words)
    labels = LabelSet(x='x',
                      y='y',
                      text='words',
                      level='glyph',
                      text_font_size="9pt",
                      x_offset=5,
                      y_offset=5,
                      source=source,
                      render_mode='canvas')

    hover = plot.select(dict(type=HoverTool))
    hover.tooltips = {"word": "@words"}
    # df.transform(lambda x: list(zip(x, df[2])))
    if line_data is True:
        end_arrow = OpenHead(line_color="firebrick", line_width=1, size=10)
        for i in range(1, len(df_words.index), 2):
            x_start, y_start = df_words.iloc[i - 1]['x'], df_words.iloc[i -
                                                                        1]['y']
            x_end, y_end = df_words.iloc[i]['x'], df_words.iloc[i]['y']
            plot.add_layout(
                Arrow(end=end_arrow,
                      x_start=x_start,
                      y_start=y_start,
                      x_end=x_end,
                      y_end=y_end))

    plot.add_layout(labels)
    show(plot, notebook_handle=True)
コード例 #11
0
def test_whisker(output_file_url, selenium, screenshot):

    x_range = Range1d(0, 10)
    y_range = Range1d(0, 10)

    # Have to specify x/y range as labels aren't included in the plot area solver
    plot = Plot(plot_height=HEIGHT, plot_width=WIDTH,
                x_range=x_range, y_range=y_range, toolbar_location=None)

    source = ColumnDataSource(data=dict(
        x1 = [1,3,5,7,9],
        lower1 = [1,2,1,2,1],
        upper1 = [2,3,2,3,2],
        x2 = [200, 250, 350, 450, 550],
        lower2 = [400, 300, 400, 300, 400],
        upper2 = [500, 400, 500, 400, 500],
    ))

    whisker1 = Whisker(base='x1', lower='lower1', upper='upper1',
                       line_width=3, line_color='red', line_dash='dashed',
                       source=source)

    whisker2 = Whisker(base='x2', lower='lower2', upper='upper2', upper_head=OpenHead(),
                       base_units='screen', lower_units='screen', upper_units='screen',
                       dimension='width', line_width=3, line_color='green',
                       source=source)

    plot.add_layout(whisker1)
    plot.add_layout(whisker2)

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Take screenshot
    screenshot.assert_is_valid()
コード例 #12
0
               source=H_dist_source)
H_dist_label = LatexLabelSet(x='xL', y='yL', text='text', source=H_dist_source)

D_dist = Arrow(end=TeeHead(line_color="#808080", line_width=1, size=10),
               start=TeeHead(line_color="#808080", line_width=1, size=10),
               x_start='xS',
               y_start='yS',
               x_end='xE',
               y_end='yE',
               line_width=1,
               line_color="#808080",
               source=D_dist_source)
D_dist_label = LatexLabelSet(x='xL', y='yL', text='text', source=D_dist_source)

T1_arrow_glyph = Arrow(end=OpenHead(line_color="#333333",
                                    line_width=4,
                                    size=10),
                       x_start='xS',
                       y_start='yS',
                       x_end='xE',
                       y_end='yE',
                       line_width=4,
                       source=T1_source,
                       line_color="#333333")

T2_arrow_glyph = Arrow(end=OpenHead(line_color="#333333",
                                    line_width=4,
                                    size=10),
                       x_start='xS',
                       y_start='yS',
                       x_end='xE',
コード例 #13
0
    def _create_arrows(fig_handle, plot_width):

        x0 = plot_width * 0.55

        all_arrows = []
        for i in range(ATM_MAX_LAYERS + 1):
            layer_arrows = []

            for j in range(ATM_MAX_LAYERS + 1):

                if i == j:
                    head = NormalHead(fill_color=IR_COLOR_HOT)
                    head2 = NormalHead(fill_color=IR_COLOR_HOT)
                    l_alpha = 1.0
                else:
                    l_alpha = 0.8
                    head = OpenHead(line_color=IR_COLOR_HOT,
                                    line_alpha=l_alpha)
                    head2 = OpenHead(line_color=IR_COLOR_HOT,
                                     line_alpha=l_alpha)

                data_src = ColumnDataSource(data=dict(
                    x_start=[x0], x_end=[x0], y_start=[0], y_end=[1]))
                data_src2 = ColumnDataSource(data=dict(
                    x_start=[x0], x_end=[x0], y_start=[0], y_end=[1]))

                up_arrow = Arrow(end=head,
                                 x_start='x_start',
                                 x_end='x_end',
                                 y_start='y_start',
                                 y_end='y_end',
                                 line_color=IR_COLOR_HOT,
                                 line_alpha=l_alpha,
                                 source=data_src)

                down_arrow = Arrow(end=head2,
                                   x_start='x_start',
                                   x_end='x_end',
                                   y_start='y_start',
                                   y_end='y_end',
                                   line_color=IR_COLOR_HOT,
                                   line_alpha=l_alpha,
                                   source=data_src2)

                up_arrow.visible = False
                down_arrow.visible = False

                if j < i:
                    fig_handle.add_layout(up_arrow)
                    layer_arrows.append((up_arrow, ))
                elif j == i:
                    fig_handle.add_layout(up_arrow)

                    if i == 0:
                        layer_arrows.append((up_arrow, ))
                    else:
                        fig_handle.add_layout(down_arrow)
                        layer_arrows.append((up_arrow, down_arrow))
                else:
                    if i != 0:
                        fig_handle.add_layout(down_arrow)
                        layer_arrows.append((down_arrow, ))

            all_arrows.append(layer_arrows)

        return all_arrows
コード例 #14
0
from bokeh.plotting import figure, output_file, show
from bokeh.models import Arrow, OpenHead, NormalHead, VeeHead

output_file("arrow.html", title="arrow.py example")

p = figure(plot_width=600,
           plot_height=600,
           x_range=(-0.1, 1.1),
           y_range=(-0.1, 0.8))

p.circle(x=[0, 1, 0.5],
         y=[0, 0, 0.7],
         radius=0.1,
         color=["navy", "yellow", "red"],
         fill_alpha=0.1)

p.add_layout(Arrow(end=OpenHead(), x_start=0, y_start=0, x_end=1, y_end=0))
p.add_layout(
    Arrow(end=NormalHead(), x_start=1, y_start=0, x_end=0.5, y_end=0.7))
p.add_layout(Arrow(end=VeeHead(), x_start=0.5, y_start=0.7, x_end=0, y_end=0))

show(p)
コード例 #15
0
ファイル: Person.py プロジェクト: Irfan6220c/Test
def create_arrows_velocityDiagram( diagram, colors, boatSpeed ):
    # Create arrows for the boat
    boatArrows_sources = list()
    boatArrows_intities = list()
    
    boatColors = ['#000000']+colors
    for i in range(0,6):
        boatArrows_sources.append(ColumnDataSource(data=dict(xs=[5],ys=[0],xe=[5],ye=[0])))
        boatArrows_intities.append(
                                   Arrow(    
                                            end=OpenHead(
                                                         line_color=boatColors[i],
                                                         line_width=3,
                                                         size=5
                                                        ),
                                            x_start=['xs'][0],
                                            y_start=['ys'][0],
                                            x_end=['xe'][0], 
                                            y_end=['ye'][0], 
                                            line_color=boatColors[i],
                                            source=boatArrows_sources[i]
                                        ) 
                                  )
        diagram.add_layout( boatArrows_intities[i] )                      
        
    boatArrows_sources[0].data = dict(
                                        xs=[5],ys=[0],xe=[5],ye=[boatSpeed]
                                     )
                                            
    # Create arrows for the swimmers
    swimmerArrows_sources = list()
    swimmerArrows_intities = list()
    
    for i in range(0,5):
        xPos = float(i*5+10)
        swimmerArrows_sources.append(
                                     [ ColumnDataSource(data=dict(xs=[xPos],ys=[boatSpeed],xe=[xPos],ye=[boatSpeed])),
                                       ColumnDataSource(data=dict(xs=[xPos+0.5],ys=[0],xe=[xPos+0.5],ye=[0])),
                                       ColumnDataSource(data=dict(xs=[xPos-0.5],ys=[0],xe=[xPos-0.5],ye=[boatSpeed])) ]
                                    )
        
        relativeVelocityArrow = Arrow(    
                                            end=OpenHead(
                                                         line_color="#DAD7CB",
                                                         line_width=3,
                                                         size=5
                                                        ),
                                            x_start=['xs'][0],
                                            y_start=['ys'][0],
                                            x_end=['xe'][0], 
                                            y_end=['ye'][0], 
                                            line_color = "#DAD7CB",
                                            source=swimmerArrows_sources[i][0]
                                        ) 
        absoluteVelocityArrow = Arrow(    
                                            end=OpenHead(
                                                         line_color=colors[i],
                                                         line_width=3,
                                                         size=5
                                                        ),
                                            x_start=['xs'][0],
                                            y_start=['ys'][0],
                                            x_end=['xe'][0], 
                                            y_end=['ye'][0],
                                            line_color=colors[i],
                                            source=swimmerArrows_sources[i][1]
                                        ) 
                                            
        startingVelocityArrow = Arrow(    
                                            end=OpenHead(
                                                         line_color="#000000",
                                                         line_width=3,
                                                         size=5
                                                        ),
                                            x_start=['xs'][0],
                                            y_start=['ys'][0],
                                            x_end=['xe'][0], 
                                            y_end=['ye'][0], 
                                            line_color = "#000000",
                                            source=swimmerArrows_sources[i][2]
                                        ) 
                                            
        swimmerArrows_intities.append( [relativeVelocityArrow, absoluteVelocityArrow, startingVelocityArrow] )
                                            
        diagram.add_layout( relativeVelocityArrow )
        diagram.add_layout( absoluteVelocityArrow )
        diagram.add_layout( startingVelocityArrow )
    
    # Create labels for both the boat and the swimmers
    diagram.add_layout( Label(
                                  x=5, y=-2,
                                  text='Boat',
                                  text_color='black',text_font_size="8pt",
                                  level='glyph',text_baseline="middle",text_align="center",
                              ))
    diagram.add_layout( Label(
                                  x=10, y=-2,
                                  text='Orange Swimmer',
                                  text_color='black',text_font_size="8pt",
                                  level='glyph',text_baseline="middle",text_align="center",
                              ))
    diagram.add_layout( Label(
                                  x=15, y=-2,
                                  text='Green Swimmer',
                                  text_color='black',text_font_size="8pt",
                                  level='glyph',text_baseline="middle",text_align="center",
                              ))
    diagram.add_layout( Label(
                                  x=20, y=-2,
                                  text='Blue Swimmer',
                                  text_color='black',text_font_size="8pt",
                                  level='glyph',text_baseline="middle",text_align="center",
                              ))
    diagram.add_layout( Label(
                                  x=25, y=-2,
                                  text='Yellow Swimmer',
                                  text_color='black',text_font_size="8pt",
                                  level='glyph',text_baseline="middle",text_align="center",
                              ))
    diagram.add_layout( Label(
                                  x=30, y=-2,
                                  text='Red Swimmer',
                                  text_color='black',text_font_size="8pt",
                                  level='glyph',text_baseline="middle",text_align="center",
                              ))
    '''
    swimmersLabels = list()
    for i in range(0,5):
        xPos = i*5+10
        swimmersLabels.append(
                               LabelSet(
                                          x=xPos, y=-2,
                                          text='f',
                                          text_color='black',text_font_size="15pt",
                                          level='glyph',text_baseline="middle",text_align="center",
                                       )
                             )
        diagram.add_layout( swimmersLabels[i] )
    '''
    return boatArrows_sources, swimmerArrows_sources
コード例 #16
0
x_range = Range1d(0, 10)
y_range = Range1d(0, 10)

# Have to specify x/y range as labels aren't included in the plot area solver
plot = Plot(plot_width=600, plot_height=600,
            x_range=x_range, y_range=y_range, toolbar_location=None)

source = ColumnDataSource(data=dict(
    x1 = [1,3,5,7,9],
    lower1 = [1,2,1,2,1],
    upper1 = [2,3,2,3,2],
    x2 = [200, 250, 350, 450, 550],
    lower2 = [400, 300, 400, 300, 400],
    upper2 = [500, 400, 500, 400, 500],
))

whisker1 = Whisker(base='x1', lower='lower1', upper='upper1',
                   line_width=3, line_color='red', line_dash='dashed',
                   source=source)

whisker2 = Whisker(base='x2', lower='lower2', upper='upper2', upper_head=OpenHead(),
                   base_units='screen', lower_units='screen', upper_units='screen',
                   dimension='width', line_width=3, line_color='green',
                   source=source)

plot.add_layout(whisker1)
plot.add_layout(whisker2)

save(plot)
コード例 #17
0
from bokeh.plotting import figure, output_file, show
from bokeh.models import Arrow, OpenHead, NormalHead, VeeHead

output_file("arrow.html", title="arrow.py example")

p = figure(plot_width=600, plot_height=600)

p.circle(x=[0, 1, 0.5],
         y=[0, 0, 0.7],
         radius=0.1,
         color=["navy", "yellow", "red"],
         fill_alpha=0.1)

p.add_layout(
    Arrow(end=OpenHead(line_color="firebrick", line_width=4),
          x_start=0,
          y_start=0,
          x_end=1,
          y_end=0))

p.add_layout(
    Arrow(end=NormalHead(fill_color="orange"),
          x_start=1,
          y_start=0,
          x_end=0.5,
          y_end=0.7))

p.add_layout(
    Arrow(end=VeeHead(size=35),
          line_color="red",
          x_start=0.5,
コード例 #18
0
plot_main.axis.visible = False
plot_main.outline_line_width = 2
plot_main.outline_line_color = "Black"
plot_main.title.text_font_size = "13pt"
plot_main.toolbar.logo = None

# plot error message if both supports are set to sliding
error_label = LabelSet(x='x', y='y', text='name', source=error_msg)
plot_main.add_layout(error_label)
plot_main.add_glyph(error_msg_frame,Rect(x="x", y="y", width=8, height=1, angle=0, fill_color='red', fill_alpha=0.2))

# plot helper line
plot_main.add_glyph(aux_line, aux_line_glyph)

# measures
beam_measure_doublearrow_glyph = Arrow(start=OpenHead(line_color=c_black, line_width=2, size=8), end=OpenHead(line_color='black',line_width= 2, size=8),
    x_start=xr_start, y_start=-1.2, x_end=xr_end, y_end=-1.2, line_width=5, line_color=c_black)
beam_measure_singlearrow_glyph = Arrow(end=NormalHead(fill_color=c_gray, line_width=1, size=6),
    x_start=xr_start-0.1, y_start=-0.8, x_end=xr_start+0.8, y_end=-0.8, line_width=1, line_color=c_black)

beam_measure_label_source.data = dict(x=[xr_start+0.25, 0.5*(xr_end-xr_start)], y=[-0.7,-1.6], text=["x","L"])
beam_measure_label = LatexLabelSet(x='x', y='y', text='text', source=beam_measure_label_source, level='glyph')#, x_offset=3, y_offset=-15)
plot_main.line(x=[xr_start, xr_start], y=[-0.7,-0.9], line_color=c_black) # vertical line for single x-arrow
plot_main.add_layout(beam_measure_singlearrow_glyph)
plot_main.add_layout(beam_measure_doublearrow_glyph)
plot_main.add_layout(beam_measure_label)


# graphics for a cold beam
snow_images = ["Normal_Force_Rod/static/images/snowflake01.svg",
               "Normal_Force_Rod/static/images/snowflake02.svg",
コード例 #19
0
            width=0.1,
            height=0.1,
            source=PendulumElbow,
            color="#808080")
fig.ellipse(x='x', y='y', width=1, height=1, source=Mass, color="#0065BD")
fig.patch(x='x', y='y', source=KinEnergySource, color="#E37222")
fig.patch(x='x', y='y', source=OtherEnergySource, color="#808080")
fig.line(x='x', y='y', source=PhiAngle, color="black")
fig.text(x='x',
         y='y',
         text='t',
         source=PhiAngleText,
         color="black",
         text_baseline="top",
         text_align="center")
arrow_glyph = Arrow(end=OpenHead(line_color="black", line_width=2, size=6),
                    x_start='xs',
                    y_start='ys',
                    x_end='xe',
                    y_end='ye',
                    source=dPhiArrow,
                    line_color="black",
                    line_width=2)
fig.add_layout(arrow_glyph)
dPhiText = fig.text(x='x',
                    y='y',
                    text='t',
                    source=dPhiArrowText,
                    color="black",
                    text_align="left")
コード例 #20
0
from bokeh.io import save
from bokeh.models import Arrow, NormalHead, OpenHead, TeeHead, VeeHead
from bokeh.plotting import figure

# Have to specify x/y range as labels aren't included in the plot area solver
plot = figure(width=600, height=600, x_range=(0,10), y_range=(0,10), toolbar_location=None)

arrow1 = Arrow(x_start=1, y_start=4, x_end=6, y_end=9,
               line_color='green', line_alpha=0.7,
               line_dash='8 4', line_width=5, end=OpenHead()
               )
arrow1.end.line_width=8

arrow2 = Arrow(x_start=2, y_start=3, x_end=7, y_end=8,
               start=NormalHead(), end=VeeHead()
               )
arrow2.start.fill_color = 'indigo'
arrow2.end.fill_color = 'orange'
arrow2.end.size = 50

plot.add_layout(arrow1)
plot.add_layout(arrow2)

# test arrow body clipping
plot.add_layout(Arrow(start=TeeHead(line_width=1), x_start=6, y_start=5, x_end=8, y_end=6, line_width=10))
plot.add_layout(Arrow(start=VeeHead(line_width=1, fill_color="white"), x_start=6, y_start=4, x_end=8, y_end=5, line_width=10))
plot.add_layout(Arrow(start=NormalHead(line_width=1, fill_color="white"), x_start=6, y_start=3, x_end=8, y_end=4, line_width=10))
plot.add_layout(Arrow(start=OpenHead(line_width=1), x_start=6, y_start=2, x_end=8, y_end=3, line_width=10))

save(plot)
コード例 #21
0

#adding arrows to edges to make it a directed graph
start_coord = [[.95, .117], [.97, -.07], [.9, -.1], [.64,
                                                     .7257], [.625, .6691],
               [-.15, .9357], [0, .9], [.05, .878], [-.65, .5785], [-.65, .65],
               [-.94, -.14], [-.9, -.1], [-.85, -.0618], [-.6, -.7],
               [-.6, -.743], [.1, -.957], [.1, -.9]]
end_coord = [[.72, .653], [.73, -.63], [.1, -.9], [.1, .957], [-.84, .06],
             [-.61, .738], [0, -.9], [.585, -.4207], [-.12, -.708], [.6, -.6],
             [-.75, -.5833], [-.1, -.9], [.54, -.631], [.6, -.7], [-.2, -.914],
             [.6, -.743], [.9, -.1]]
for i in range(0, 17):
    plot.add_layout(
        Arrow(end=OpenHead(line_color="black",
                           line_width=2,
                           size=10,
                           line_alpha=.65),
              x_start=start_coord[i][0],
              y_start=start_coord[i][1],
              x_end=end_coord[i][0],
              y_end=end_coord[i][1],
              line_alpha=0.25))

#function called when button is pressed
time_slider.on_change('value', update_data_bubble)
button = Button(label='► Play', width=120, margin=(1, 1, 1, 20))
button.on_click(animate)

#adding descriptive info
note1 = Div(
    text=
コード例 #22
0
    children_visual.append(visual)

# plot force symbols
for force_symbol in deformable_object.force_symbols:
    # sigma
    source = force_symbol.data_source['sigma']
    visual = Patch(x='x',
                   y='y',
                   line_color=c_black,
                   line_width=1,
                   fill_color=c_orange,
                   fill_alpha=0.75)
    figure.add_glyph(source, visual)
    # sigma arrows
    source = force_symbol.data_source['sigma_arrows']
    visual = Arrow(end=OpenHead(line_color=c_black, line_width=1, size=5),
                   x_start='xS',
                   y_start='yS',
                   x_end='xE',
                   y_end='yE',
                   line_color=c_black,
                   line_width=1,
                   source=source)
    figure.add_layout(visual)
    # R arrows
    source = force_symbol.data_source['R_arrow']
    visual = Arrow(end=OpenHead(line_color=c_black, line_width=2, size=10),
                   x_start='xS',
                   y_start='yS',
                   x_end='xE',
                   y_end='yE',
コード例 #23
0
ファイル: whisker.py プロジェクト: zmj2008/bokeh
    upper1=[2, 3, 2, 3, 2],
    x2=[200, 250, 350, 450, 550],
    lower2=[400, 300, 400, 300, 400],
    upper2=[500, 400, 500, 400, 500],
))

whisker1 = Whisker(base='x1',
                   lower='lower1',
                   upper='upper1',
                   line_width=3,
                   line_color='red',
                   line_dash='dashed',
                   source=source)

whisker2 = Whisker(base='x2',
                   lower='lower2',
                   upper='upper2',
                   upper_head=OpenHead(),
                   base_units='screen',
                   lower_units='screen',
                   upper_units='screen',
                   dimension='width',
                   line_width=3,
                   line_color='green',
                   source=source)

plot.add_layout(whisker1)
plot.add_layout(whisker2)

save(plot)
コード例 #24
0
figure_name.add_glyph(
    cds_support_left,
    ImageURL(url="sp_img", x='x', y='y', w=0.66, h=0.4, anchor="center"))
figure_name.add_glyph(
    cds_support_right,
    ImageURL(url="sp_img",
             x='x',
             y='y',
             w=support_width,
             h=support_height,
             anchor="center"))

### add arrows to the figure ###
# use either Normalheads or Openheads and orange color by default
#arrow_glyph = Arrow(end=NormalHead(line_color=c_orange, fill_color=c_orange), x_start='xS', y_start='yS', x_end='xE', y_end='yE', line_color=c_orange, source=cds_arrow)
arrow_glyph = Arrow(end=OpenHead(line_color=c_orange),
                    x_start='xS',
                    y_start='yS',
                    x_end='xE',
                    y_end='yE',
                    line_color=c_orange,
                    source=cds_arrow)
figure_name.add_layout(arrow_glyph)

### define the 3D plot ###
x = np.arange(0, 300, 10)
y = np.arange(0, 300, 10)
xx, yy = np.meshgrid(x, y)
xx = xx.ravel()
yy = yy.ravel()
value = np.sin(xx / 50) * np.cos(yy / 50) * 50 + 50
コード例 #25
0
plot.title.text_color = "black"
plot.title.text_font_style = "bold"
plot.title.align = "center"


labels1 = LabelSet(x='x', y='y', text='name', level='glyph',
              x_offset=0, y_offset=0, source=f1.label, render_mode='canvas')
labels2 = LabelSet(x='x', y='y', text='name', level='glyph',
              x_offset=0, y_offset=0, source=f2.label, render_mode='canvas')

#P arrow:
p1_arrow_glyph = Arrow(end=NormalHead(line_color="#0065BD",line_width= 4, size=10),
    x_start='xS', y_start='yS', x_end='xE', y_end='yE',line_width= "lW", source=f1.arrow_source,line_color="#0065BD")
p2_arrow_glyph = Arrow(end=NormalHead(line_color="#E37222",line_width= 4, size=10),
    x_start='xS', y_start='yS', x_end='xE', y_end='yE',line_width= "lW", source=f2.arrow_source,line_color="#E37222")
e1_arrow_glyph = Arrow(end=OpenHead(line_color="#A2AD00",line_width= 1, size=7),
    x_start='xS', y_start='yS', x_end='xE', y_end='yE',line_width= "lW", source=f1.e_s,line_color="#A2AD00")
e2_arrow_glyph = Arrow(end=OpenHead(line_color="#A2AD00",line_width= 1, size=7),
    x_start='xS', y_start='yS', x_end='xE', y_end='yE',line_width= "lW", source=f2.e_s,line_color="#A2AD00")


plot.add_layout(p1_arrow_glyph)
plot.add_layout(p2_arrow_glyph)
plot.add_layout(e1_arrow_glyph)
plot.add_layout(e2_arrow_glyph)
plot.add_layout(labels1)
plot.add_layout(labels2)



#curdoc().add_root( row(column(f1.mag_slider,f1.loc_slider,f2.mag_slider,f2.loc_slider, toggle),plot ) )
コード例 #26
0
        arrow_source.data = dict(xS= [x[f_coord1]], xE= [x[f_coord1]], yS= [y[f_coord1]-1-(f_mag/200.0)], yE=[y[f_coord1]-1])


print(len(x))
print(len(y))


def init_data():
    fun_change(None,None,None)


# Plotting
plot = Figure(title="Maxwell reciprocity", x_range=[x0-3,xf+3], y_range=[-15,15.1])
plot.line(x='x', y='y', source=data_source, color='blue',line_width=5)
#Callback
force_loc.on_change('value', fun_change)
force_input.on_change('value', fun_change)

#arrow plotting:
arrow_glyph = Arrow(end=OpenHead(line_color="red",line_width= 4,size=10),
    x_start='xS', y_start='yS', x_end='xE', y_end='yE',source=arrow_source,line_color="red",line_width=2)
plot.add_layout(arrow_glyph)

#main:
init_data()


#Layout
#show(row(column(force_loc,force_input),plot))
curdoc().add_root(row(column(force_loc,force_input),plot))
コード例 #27
0
ファイル: yau_bases.py プロジェクト: saidatta97/squiggle
from bokeh.models import Arrow, OpenHead, NormalHead, VeeHead
from bokeh.layouts import gridplot

output_file("yau_bases.html")

p = figure(plot_width=500, plot_height=350, title="Yau's vectors")

# plot the lines
p.line(x=[0, 0.5], y=[0, (3**0.5) / 2], color="red", legend="T")
p.line(x=[0, (3**0.5) / 2], y=[0, 0.5], color="black", legend="C")
p.line(x=[0, (3**0.5) / 2], y=[0, -0.5], color="green", legend="G")
p.line(x=[0, 0.5], y=[0, -(3**0.5) / 2], color="blue", legend="A")

# plot the arrows
p.add_layout(
    Arrow(end=OpenHead(size=10),
          line_color="blue",
          x_start=0,
          y_start=0,
          x_end=0.5,
          y_end=-(3**0.5) / 2))
p.add_layout(
    Arrow(end=OpenHead(size=10),
          line_color="red",
          x_start=0,
          y_start=0,
          x_end=0.5,
          y_end=(3**0.5) / 2))
p.add_layout(
    Arrow(end=OpenHead(size=10),
          line_color="green",
コード例 #28
0
def test_arrow(output_file_url, selenium, screenshot):

    # Have to specify x/y range as labels aren't included in the plot area solver
    plot = figure(height=HEIGHT,
                  width=WIDTH,
                  x_range=(0, 10),
                  y_range=(0, 10),
                  tools='',
                  toolbar_location="above")

    arrow1 = Arrow(x_start=1,
                   y_start=3,
                   x_end=6,
                   y_end=8,
                   line_color='green',
                   line_alpha=0.7,
                   line_dash='8 4',
                   line_width=5,
                   end=OpenHead())
    arrow1.end.line_width = 8

    arrow2 = Arrow(x_start=2,
                   y_start=2,
                   x_end=7,
                   y_end=7,
                   start=NormalHead(),
                   end=VeeHead())
    arrow2.start.fill_color = 'indigo'
    arrow2.end.fill_color = 'orange'
    arrow2.end.size = 50

    plot.add_layout(arrow1)
    plot.add_layout(arrow2)

    # test arrow body clipping
    plot.add_layout(
        Arrow(start=VeeHead(line_width=1, fill_color="white"),
              x_start=6,
              y_start=4,
              x_end=8,
              y_end=5,
              line_width=10))
    plot.add_layout(
        Arrow(start=NormalHead(line_width=1, fill_color="white"),
              x_start=6,
              y_start=3,
              x_end=8,
              y_end=4,
              line_width=10))
    plot.add_layout(
        Arrow(start=OpenHead(line_width=1),
              x_start=6,
              y_start=2,
              x_end=8,
              y_end=3,
              line_width=10))

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Take screenshot
    screenshot.assert_is_valid()
コード例 #29
0
          y=[u22.data['y'][0]-0.05, u22.data['y'][0]+0.05], line_color="White")
plot.line(x=[u22.data['x'][0], u22.data['x'][0]],
          y=[u22.data['y'][0]-0.05, u22.data['y'][0]+0.05], line_color="White")
plot.add_layout(Label(x=-0.5, y=-1.3, text='ε(%s=22)'%ofilt, text_color="White",
                      text_font_size='8pt'))

plot.line(x='x', y='y', line_color="White", line_cap='butt',
             source=u24)
plot.line(x=[-u24.data['x'][0], -u24.data['x'][0]],
          y=[u24.data['y'][0]-0.05, u24.data['y'][0]+0.05], line_color="White")
plot.line(x=[u24.data['x'][0], u24.data['x'][0]],
          y=[u24.data['y'][0]-0.05, u24.data['y'][0]+0.05], line_color="White")
plot.add_layout(Label(x=-0.5, y=-1.55, text='ε(%s=24)'%ofilt, text_color="White",
                      text_font_size='8pt'))

plot.add_layout(Arrow(end=OpenHead(line_color="White", size=10),
                      x_start=-0.350, y_start=3.3, x_end=-0.45, y_end=3.3,
                      line_color="White"))

plot.add_layout(Arrow(end=OpenHead(line_color="White", size=10),
                      x_start=0.8, y_start=3.3, x_end=0.9, y_end=3.3,
                      line_color="White"))

plot.add_layout(Arrow(end=OpenHead(line_color="firebrick", size=10),
                      x_start=0.9, y_start=2.5, x_end=0.9, y_end=3.0,
                      line_color="firebrick"))

plot.add_layout(Arrow(end=OpenHead(line_color="steelblue", size=10),
                      x_start=0.9, y_start=-0.7, x_end=0.9, y_end=-1.4,
                      line_color="steelblue"))
コード例 #30
0
    y_range=(0.99 * all_layer_Hl, -0.3 * H),
    plot_width=200,
    plot_height=400,
    toolbar_location=None,
    toolbar_sticky=False)

sigma_patch = Patch(x='x', y='y', fill_color='#EEEEEE', line_color='black')
sigma_figure.add_glyph(sigma_data, sigma_patch)

force = PolyArea(x_sigma_all, y_sigma_all) * np.cos(np.radians(omega))

arrow_data = ColumnDataSource(data=dict(
    x0=[max(x_sigma_all)], y0=[load_height_top], y1=[load_height_top]))

force_arrow = Arrow(end=OpenHead(line_color="black",
                                 line_width=3,
                                 line_join='bevel'),
                    line_width=3,
                    x_start='x0',
                    y_start='y0',
                    x_end=0,
                    y_end='y1',
                    source=arrow_data)
sigma_figure.add_layout(force_arrow)

arrow_load = Label(x=0.27 * max(x_sigma_all),
                   y=load_height_top,
                   text='{:.0f} kN'.format(force),
                   text_font_style='bold',
                   border_line_width=2,
                   text_font_size='16pt',