circle ( x, y, size = 5, color = 'red', legend_label = 'circle' ) f. line ( x, y, line_width = 2, color = "blue", legend_label = 'line' ) f. For example, clicking the line legend will hide the line plot, in the output of the following script.įinally, call the show() function on the figure object to display the chart.įrom otting import figure, output_notebook, show import numpy as np x = list ( range ( 11 )) y = output_notebook () f = figure ( plot_width = 400, plot_height = 400 ) f. Setting the legend.click_policy to hide allows you to hide legends by clicking on the legend values. You can then pass the line width, color, and the label for the legend to line_width, color, and legend_label attributes, respectively. Once this is done, you can plot any plot using this figure object.įor example, to make a line plot, use the line() function and pass it the x and y coordinates of your line. You can optionally pass the width and height of your plot here. Next, you need to create a figure object. Otherwise, the plot will be displayed in your default browser. If you want to display the chart inside a Python notebook, you must call the output_notebook() function. To plot a chart with Bokeh, you need to import a figure object, then import the output_notebook and show functions from the otting module. In a later section, we’ll explain how to plot charts with the Pandas-Bokeh library. We have used bokeh LogColorMapper which maps the count of store per state to a particular color in the selected color palette.This section will show how to make charts with the Python Bokeh library. We have then created single dictionary consisting of this data which will be used as a source of a choropleth map. We have also merged Starbucks store counts per state data with this boundary data so that we have all data available in a single dataframe. We'll be using this list of latitude and longitudes to create a polygon consisting of the US state by using the patches() glyph of bokeh. We'll load it as a pandas dataframe so that we have each state’s boundary latitude and longitude data. We'll be first loading US states boundary data which is available in bokeh as a part of _states. It'll color code states of the US according to the count of Starbucks stores in that state. The first choropleth map that we'll plot using bokeh is Starbucks store count per US states. It does not need any tile providers or latitude/longitude information. The process of plotting choropleth maps using bokeh is different from previous chart types. The third chart type that we'll introduce using bokeh is a choropleth map. United States Starbucks Store Count Per State Choropleth Map ¶ We have also used tooltip which highlights the source country, the destination country, and a number of flights to that country. We have used line and circle glyphs of bokeh to plot a line between the source and destination of flight and highlight source and destinations. We have used STAMEN_TONER and ESRI_IMAGERY tiles for this chart. We'll then convert source and destination latitude/longitude data to web Mercator projection and add it to the dataframe for later use. We'll then aggregate data to keep all combinations of flights from Brazil to other countries to get a count of flights from brazil to all other countries. We'll first filter the brazil flight dataset to keep only rows where the source country is brazil. The connection map that we'll plot using the Brazil flights dataset will show flights from brazil to all other countries along with their count when hovered over the endpoint of the edge. We'll follow the same steps as mentioned earlier but will use the Brazil flight dataset this time for explanation purposes. The second type of chart that we'll be plotting using bokeh is a connection map. įlights From Brazil To Other Countries Connection Map ¶
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |