Parameter - scale_width is used, so that width of plots is adjusted accordingly to the width of the window. we combined these plots using the row function. In the above code, as we can see, we used three renders - circle, triangle, and Square to plot three plots. Subplots using Bokeh: from bokeh.layouts import row from otting import figure, show x = df.values y1 = df.values y2 = df.values 圓 = df.values # create three plots with one renderer each s1 = figure(width=250, height=250, background_fill_color="#fafafa") s1.circle(x, y1, size=12, color="#53777a", alpha=0.8) s2 = figure(width=250, height=250, background_fill_color="#fafafa") s2.triangle(x, y2, size=12, color="#c02942", alpha=0.8) s3 = figure(width=250, height=250, background_fill_color="#fafafa") s3.square(x, 圓, size=12, color="#d95b43", alpha=0.8) # put the results in a row that adjusts accordingly show(row(children=, sizing_mode="scale_width")) In the circle plot, I tried to show a few additional parameters which we can use, such as fill_color - to fill the circle, fill_alpha - opacity of color, line_color - Border color for the circle, and size - radius of the circle. Here, In the above code, we have used three different renders - vbar, line, and circle. To Explore interactiveness, download the plot above in HTML Format from here.Ĭombining multiple plots with different renders: #Combining mutliple plots with different renders from otting import figure, show x = df.values y1 = df.values y2 = df.values 圓 = df.values p = figure(title="Multiple Plots", x_axis_label="X Values", y_axis_label="Y Values") p.vbar(x=x, top=y1, legend_label="y1", color="skyblue", width=0.5, bottom=0) p.line(x, y2, legend_label="y2", color="black", line_width=2) p.circle(x,圓,legend_label="圓",fill_color="red",fill_alpha=0.5,line_color="yellow",size=10) # show the results show(p) To visualize the plots and make them interactive, Bokeh provides a few tools, as shown in the above plot - Pan, Box Zoom, Wheel Zoom, Save, and Reset. The parameters which we passed are x, y - Data, Legened_label - representing the label for y data, line_width - width of the line plot. The line() method is used to create the line plot.We can add additional options such as title, x_axis_label and y_axis_label for figure(). The figure is created using the figure() method.In the above code, after importing the data. from otting import figure, show, output_notebook x = df.values y = df.values # create a new plot with a title and axis labels p = figure(title="Line Plot x VS y", x_axis_label="X Values", y_axis_label="Y Values") # add a line renderer with legend and line thickness p.line(x, y, legend_label="y", line_width=2) # show the results output_notebook() show(p) To show the figure, the show function is used, and output_notebook is used explicitly when we want to Visualize the plot in the notebook. We need to import figures from Bokeh to create the figure. Importing libraries from otting import figure, show, output_notebook Installing Bokeh using Python - pip install bokeh Let’s start creating a line plot using Bokeh Dataset used can be found here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |