Discover dynamic data visualization with Python Bokeh, featuring interactive graphs and easy examples.
Python Bokeh is one of the best Python packages for data visualization. Today, we are going to see some Python Bokeh Examples. I have also provided the Python Bokeh project source code on GitHub. Learn this easy visualization tool and add it to your Python stack.
What is Python Bokeh? Python is a data visualization tool, or we can also say Python Bokeh is used to plot various types of graphs. There are various other graph plotting libraries like matplotlib, but Python Bokeh graphs are dynamic in nature, which means you can interact with the generated graph. See the below examples… Bokeh Installation 💻: Python Bokeh can be easily installed using PIP. You can install the Python Bokeh easily by running the command: pip install bokeh Now everything is ready, let’s go through the examples 🏃♂️… 1. LinePlot from bokeh.plotting import figure, show, output_notebook x= y= p=figure p.line output_notebook show | | Live Preview Source Code 🌿 Contribute 2. Scatter Plot from bokeh.plotting import figure, show, output_notebook x= y= p=figure p.circle output_notebook show 3. Bar Chart from bokeh.plotting import figure, show, output_notebook categories= values= p=figure p.vbar output_notebook show 4. Histogram from bokeh.plotting import figure, show, output_notebook import numpy as np data=np.random.normal p=figure p.hist output_notebook show 5. Pie Chart from bokeh.plotting import figure, show, output_notebook labels= values= p=figure p.wedge output_notebook show | | Live Preview Source Code 🌿 Contribute 6. Time Series Plot from bokeh.plotting import figure, show, output_notebook from datetime import datetime, timedelta start=datetime end=start + timedelta x= y= p=figure p.line output_notebook show 7. Linked Brushing from bokeh.plotting import figure, show, output_notebook from bokeh.models import ColumnDataSource x1= y1= x2= y2= source=ColumnDataSource) p1=figure p1.circle p2=figure p2.circle output_notebook show 8. Hover Tooltips from bokeh.plotting import figure, show, output_notebook from bokeh.models import HoverTool x= y= p=figure p.circle hover=HoverTool p.add_tools output_notebook show 9. Annotations from bokeh.plotting import figure, show, output_notebook from bokeh.models import Arrow, VectorRenderer, Label x= y= p=figure p.circle arrow=Arrow label=Label p.add_layout p.add_layout output_notebook show 10. Custom Glyphs from bokeh.plotting import figure, show, output_notebook from bokeh.models.glyphs import Asterisk x= y= p=figure p.add_glyph) output_notebook show | | Live Preview Source Code 🌿 Contribute 11. Gridlines and Axes from bokeh.plotting import figure, show, output_notebook x= y= p=figure, y_range=) p.grid.grid_line_color="grey" p.grid.grid_line_dash= p.xaxis.axis_label="X-axis" p.yaxis.axis_label="Y-axis" p.line output_notebook show 12. Legend from bokeh.plotting import figure, show, output_notebook x1= y1= x2= y2= p=figure p.line p.line p.legend.location="top_left" output_notebook show 13. Categorical Plots from bokeh.plotting import figure, show, output_notebook fruits= counts= p=figure p.vbar p.xaxis.axis_label="Fruit" p.yaxis.axis_label="Count" p.xaxis.axis_label_text_font_size="12pt" p.yaxis.axis_label_text_font_size="12pt" output_notebook show 14. Subplots from bokeh.plotting import figure, show, output_notebook from bokeh.layouts import gridplot x1= y1= x2= y2= p1=figure p1.circle p2=figure p2.circle grid=gridplot output_notebook show 15. Interactive Plots from bokeh.plotting import figure, show, output_notebook from bokeh.models import ColumnDataSource, HoverTool, BoxSelectTool import numpy as np x=np.random.random y=np.random.random source=ColumnDataSource) p=figure p.circle hover=HoverTool p.add_tools output_notebook show | | Live Preview Source Code 🌿 Contribute 16. Linked Panning and Zooming from bokeh.plotting import figure, show, output_notebook from bokeh.models import Range1d x1= y1= x2= y2= p1=figure, y_range=Range1d) p1.circle p2=figure p2.circle output_notebook show 17. Linked Axis Ranges from bokeh.plotting import figure, show, output_notebook from bokeh.models import Range1d x1= y1= x2= y2= p1=figure, y_range=) p1.circle p2=figure p2.circle output_notebook show 18. DateTime Axis from bokeh.plotting import figure, show, output_notebook from datetime import datetime, timedelta start=datetime end=start + timedelta x= y= p=figure p.line output_notebook show 19. Heatmap from bokeh.plotting import figure, show, output_notebook import numpy as np data=np.random.rand p=figure p.image output_notebook show 20. Streamgraph from bokeh.plotting import figure, show, output_notebook from bokeh.models import ColumnDataSource import numpy as np # Generate some sample data x=np.linspace y1=np.cumsum) y2=np.cumsum) y3=np.cumsum) y4=np.cumsum) y5=np.cumsum) source=ColumnDataSource) p=figure p.area output_notebook show | | Live Preview Source Code 🌿 Contribute 21. Polar Plot from bokeh.plotting import figure, show, output_notebook import numpy as np r=np.linspace theta=np.linspace p=figure, y_range=, toolbar_location=None) p.polar output_notebook show 22. Donut Chart from bokeh.plotting import figure, show, output_notebook from bokeh.models import ColumnDataSource labels= values= source=ColumnDataSource) p=figure p.wedge p.wedge p.axis.visible=False p.grid.grid_line_color=None output_notebook show 23. Treemap from bokeh.plotting import figure, show, output_notebook from bokeh.models import TreemapRenderer, ColumnDataSource import pandas as pd # Sample data data=pd.DataFrame source=ColumnDataSource p=figure treemap=TreemapRenderer p.add_layout output_notebook show If you get any error, make sure you have installed Python pandas by using the “pip install pandas” command 24. Network Plot from bokeh.plotting import figure, show, output_notebook from bokeh.models import ColumnDataSource, HoverTool, NodesAndLinkedEdges import networkx as nx # Sample data nodes= edges= G=nx.Graph G.add_nodes_from G.add_edges_from node_positions=nx.spring_layout node_x= for node in G.nodes] node_y= for node in G.nodes] node_color= source=ColumnDataSource) p=figure, y_range=) p.add_tools) p.circle edge_x= edge_y= for start, end in edges: x0, y0=node_positions x1, y1=node_positions edge_x.append edge_x.append edge_x.append edge_y.append edge_y.append edge_y.append p.multi_line output_notebook show 25. Sankey Diagram from bokeh.plotting import figure, show, output_notebook from bokeh.models import Sankey, ColumnDataSource # Sample data flows= source=ColumnDataSource) p=figure sankey=Sankey p.renderers.append output_notebook show | | Live Preview Source Code 🌿 Contribute 26. Chord Diagram from bokeh.plotting import figure, show, output_notebook from bokeh.models import ColumnDataSource, CategoricalColorMapper import numpy as np # Sample data nodes= connections= source=ColumnDataSource, end=np.array, value=np.array )) p=figure chord=p.chord ) output_notebook show How to Contribute? Feel free to open a PR request on our GitHub repo. Steps to contribute: Fork the repo Make changes in the Forked repo and save Open a Pull Request That’s it 😄! 🌿 Contribute Conclusion In this Repo, I have shared 25+ Python Bokeh examples that can help you learn Python Bokeh. Feel free to contribute to our GitHub repo and keep it updated. Also published . here
United States Latest News, United States Headlines
Similar News:You can also read news stories similar to this one that we have collected from other news sources.
Learn Python in 8 Weeks: The 80/20 Learning Plan with Videos, Articles, and Practice ExercisesLearn Python programming in your free time following the 80/20 learning plan.
Read more »
Challenging Long-Standing Climate Assumptions: Earth Is Getting Hotter, but Soil Is Getting WetterScience, Space and Technology News 2024
Read more »
Mysterious python parasite threatens Florida's native snakes, pushing toward their 'extreme decline'A mysterious parasite from Asia is infecting snakes over most of Florida, and researchers believe it was likely brought here by invasive Burmese pythons.
Read more »
How to Backup Your DEV.to Articles Locally in Markdown FormatBack up your DEV.to articles locally in Markdown format using Python and the DEV API.
Read more »
10 Funniest Monty Python Quotes, RankedJeremy Urquhart is a writer at Collider who focuses on the Godzilla series, the films of Martin Scorsese, and anything in the action genre.
Read more »
How I Became a Python Programmer—and Fell Out of Love With the MachineWhen I started coding, I was suspicious of all the abstractions. Then I discovered the Django framework.
Read more »
