8 Popular Python Visualization Toolkit You Like Best
When it comes to creating stunning visualizations in Python, the right toolkit can make all the difference. In this article, we’ll explore eight popular Python visualization toolkits, highlighting their strengths, weaknesses, and use cases. Whether you’re a seasoned data scientist or a beginner, this article will help you choose the perfect toolkit for your next project.
01 - Matplotlib, Seaborn, and Pandas
These three packages are closely related, as Seaborn and Pandas are built on top of Matplotlib. When you use Seaborn’s df.plot or Pandas’ (), you’re essentially writing Matplotlib code. This similarity in syntax and grammar makes them a great combination for exploratory data analysis. However, for presentation-quality graphics, you may want to use a more specialized toolkit.
Here’s an example of how to create a bar graph with Matplotlib and Seaborn:
import seaborn as sns
import matplotlib.pyplot as plt
color_order = ['xkcd: cerulean', 'xkcd: ocean', 'Xkcd: black', 'xkcd: royal purple',
'Xkcd: royal purple', 'xkcd: navy blue', 'xkcd: powder blue',
'xkcd: light maroon', 'xkcd: lightish blue', 'xkcd: navy']
sns.barplot(x=top10.Team, y=top10.Salary, palette=color_order)
plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
plt.show()
02 - ggplot (2)
You may wonder why we don’t use ggplot, the popular R visualization package, in Python. While there is a Python version of ggplot, it’s not as widely used as its R counterpart. However, if you’re already familiar with ggplot, you can use the Python version, which is built on top of Pandas.
Here’s an example of how to create a simple ggplot chart:
import pandas as pd
import matplotlib.pyplot as plt
ggplot(data=df, aes(x=season_start, y=salary, color=team)) + \
geom_point() + theme(legend.position="none") + labs(title='Salary Over Time',
x='Year', y='Salary ($)')
plt.show()
03 - Bokeh
Bokeh is a powerful and beautiful visualization toolkit that’s similar to ggplot. It’s designed for creating professional graphics and business reports, with an easy-to-use interface. Here’s an example of how to create a histogram with Bokeh:
import pandas as pd
from bokeh.plotting import figure
from bokeh.io import show
counts = is_masc.sum()
resps = is_masc.columns
p2 = figure(title='Do You View Yourself As Masculine?',
x_axis_label='Response', y_axis_label='Count',
x_range=list(resps))
p2.vbar(x=resps, top=counts, width=0.6, fill_color='red', line_color='black')
show(p2)
04 - Plotly
Plotly is a strong contender in the visualization toolkit space, but it can be challenging to use. You’ll need to install an API key and register with Plotly, and the syntax can be confusing. However, Plotly offers many advantages, including interactive business reports and customization options.
Here’s an example of how to create a bar chart with Plotly:
import pandas as pd
import plotly.graph_objs as go
data = [go.Bar(x=team_ave_df.team, y=team_ave_df.turnovers_per_mp)]
layout = go.Layout(title=go.layout.Title(text='Turnovers per Minute by Team',
xref='paper', x=0),
xaxis=go.layout.XAxis(title=go.layout.xaxis.Title(text='Team',
font=dict(family='Courier New, monospace',
size=18, color='#7f7f7f'))),
yaxis=go.layout.YAxis(title=go.layout.yaxis.Title(text='Average Turnovers / Minute',
font=dict(family='Courier New, monospace',
size=18, color='#7f7f7f'))),
autosize=True, hovermode='closest')
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='jupyter-plot', sharing='public', fileopt='overwrite')
05 - Pygal
Pygal is a relatively simple drawing package that’s used to build graphical images. It’s not as widely used as other toolkits, but it’s still a great option for creating simple graphics.
Here’s an example of how to create a simple Pygal chart:
import pygal
chart = pygal.Bar()
chart.title = 'My Bar Chart'
chart.x_title = 'X-axis'
chart.y_title = 'Y-axis'
chart.add('A', [1, 2, 3])
chart.add('B', [4, 5, 6])
chart.render_to_file('my_bar_chart.svg')
06 - Networkx
Networkx is a powerful toolkit for creating network graphs. It’s based on Matplotlib, but it’s designed for creating complex network visualizations.
Here’s an example of how to create a simple Networkx graph:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_nodes_from([1, 2, 3])
G.add_edges_from([(1, 2), (2, 3)])
options = {'Node_color': 'lime', 'Node_size': 300, 'Width': 1, 'With_labels': False}
nx.draw(G, **options)
plt.show()
In conclusion, each of these eight Python visualization toolkits has its strengths and weaknesses. By understanding the unique features of each toolkit, you can choose the perfect one for your next project. Whether you’re a seasoned data scientist or a beginner, these toolkits will help you create stunning visualizations that communicate your message effectively.