Review of Python Visualization Packages: Matplotlib, Seaborn, Pandas, ggplot, Bokeh, Plotly, Pygal, and NetworkX
This article surveys eight popular Python visualization libraries—Matplotlib, Seaborn, Pandas, ggplot, Bokeh, Plotly, Pygal, and NetworkX—explaining their strengths, weaknesses, typical use‑cases, and providing concrete code examples to help readers choose the right tool for exploratory analysis or presentation.
The author introduces the challenge of selecting an attractive and functional Python visualization library and promises to cover eight widely used packages, noting that many also have equivalents in other languages.
Matplotlib, Seaborn and Pandas are discussed together because Seaborn and Pandas are built on top of Matplotlib, sharing a similar syntax and styling capabilities. Matplotlib offers low‑level control and many style presets (e.g., ggplot2, xkcd). Example code:
import seaborn as sns
import matplotlib.pyplot as plt
color_order = ['xkcd:cerulean', 'xkcd:ocean', 'xkcd:black', '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).set_title('Teams with Highest Median Salary')
plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))The author also shows a Q‑Q plot using scipy.stats :
import matplotlib.pyplot as plt
import scipy.stats as stats
log_resid = model2.predict(X_test) - y_test
stats.probplot(log_resid, dist="norm", plot=plt)
plt.title("Normal Q-Q plot")
plt.show()ggplot (the Python port of R's ggplot2) provides a grammar‑of‑graphics API but depends on an older Pandas version. A simple example:
#All Salaries
ggplot(data=df, aes(x=season_start, y=salary, colour=team)) +
geom_point() +
theme(legend.position="none") +
labs(title='Salary Over Time', x='Year', y='Salary ($)')Bokeh offers a high‑level, ggplot‑like syntax with strong interactive and reporting capabilities. Example code creates a bar chart from the 538 Masculinity Survey:
import pandas as pd
from bokeh.plotting import figure, show
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)Plotly is powerful but requires an API key and can be verbose. The author notes difficulties creating labeled charts but demonstrates a bar plot and a scatter plot:
# plot 1 - barplot
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')),
yaxis=go.layout.YAxis(title=go.layout.yaxis.Title(text='Average Turnovers/Minute')),
autosize=True, hovermode='closest')
py.iplot(figure_or_data=data, layout=layout, filename='jupyter-plot')
# plot 2 - scatterplot
data = [go.Scatter(x=player_year.minutes_played, y=player_year.salary,
marker=go.scatter.Marker(color='red', size=3))]
layout = go.Layout(title='test', xaxis=dict(title='why'), yaxis=dict(title='plotly'))
py.iplot(figure_or_data=data, layout=layout, filename='jupyter-plot2')Pygal is a lightweight library that uses a grammar‑of‑graphics approach. The workflow involves instantiating a chart, formatting attributes, and adding data with figure.add() . Rendering requires render_to_file and opening the file in a browser.
NetworkX builds on Matplotlib for graph‑theoretic visualizations. The author shows how to load a SNAP Facebook circles file, construct a graph, and draw it with custom node colors and sizes:
options = {'node_color': range(len(G)), 'node_size': 300, 'width': 1,
'with_labels': False, 'cmap': plt.cm.coolwarm}
nx.draw(G, **options)Finally, the author concludes that no single package is universally best; the choice depends on the specific scenario—quick exploratory analysis may favor Pandas or Seaborn, while polished presentations might benefit from Bokeh or Plotly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.