Which Python Visualization Library Wins? In‑Depth Comparison of 5 Tools
This article compares five popular Python visualization libraries—Matplotlib, Pyecharts, Seaborn, Plotly, and Bokeh—by drawing identical multi‑series bar charts, evaluating interactivity, aesthetics, code complexity, documentation quality, and assigning a subjective score to each.
Many readers learn Python to create impressive visualizations; the five major tools are Matplotlib, Pyecharts, Seaborn, Plotly, and Bokeh. This article evaluates them by drawing the same multi‑series bar chart with identical data and scoring each library on usability, interactivity, aesthetics, documentation, and code length.
Metric Explanation
To clearly understand the differences, the same dataset is used to produce multi‑series bar charts and the following aspects are assessed: visual appeal, interactivity, ease of coding, documentation completeness, and overall suitability for beginners.
Data Description
The data originates from Pyecharts' faker module: x is a list of brand names, while y1 and y2 are meaningless numeric series of equal length.
from pyecharts.faker import Faker
x = Faker.choose()
y1 = Faker.values()
y2 = Faker.values()1. Pyecharts
Pyecharts is a Python wrapper for Baidu's ECharts, offering over 30 chart types, rich interactivity, and extensive Chinese documentation. It creates interactive bar charts directly in notebooks.
from pyecharts import options as opts
from pyecharts.charts import Bar
c = (
Bar()
.add_xaxis(x)
.add_yaxis("商家A", y1)
.add_yaxis("商家B", y2)
.set_global_opts(title_opts=opts.TitleOpts(title="Pyecharts—柱状图", subtitle=""))
).render_notebook()The default output is an interactive, aesthetically pleasing bar chart.
Pros: interactive, beautiful default style, comprehensive Chinese docs, many chart types. Cons: does not accept pandas Series; data must be converted to plain lists.
Subjective score: 85 points.
2. Matplotlib
Matplotlib is the most widely used Python visualization library, supporting a huge variety of chart types but lacking native interactivity and Chinese font support.
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei'] width = 0.35
x1 = np.arange(len(x))
fig, ax = plt.subplots()
rects1 = ax.bar(x1 - width/2, y1, width, label='商家A')
rects2 = ax.bar(x1 + width/2, y2, width, label='商家B')
ax.set_title('Matplotlib—柱状图')
ax.set_xticks(x1)
ax.set_xticklabels(x)
ax.legend()
plt.show()Pros: extensive community resources, flexible styling. Cons: no built‑in interactivity, default colors are dull, requires more code for comparable results.
Subjective score: 77 points.
3. Plotly
Plotly provides powerful interactive charts with both online and offline modes. It offers over 30 chart types and a built‑in toolbox, but official Chinese documentation is lacking.
import plotly
import plotly.offline as py
import plotly.graph_objs as go
plotly.offline.init_notebook_mode(connected=True) trace0 = go.Bar(x=x, y=y1, name='商家A')
trace1 = go.Bar(x=x, y=y2, name='商家B')
data = [trace0, trace1]
layout = go.Layout(title={'text':'Plotly-柱状图','y':0.9,'x':0.5,'xanchor':'center','yanchor':'top'})
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)Pros: interactive, many chart types, good default colors. Cons: limited Chinese resources, occasional difficulty finding detailed parameter settings.
Subjective score: 76 points.
4. Bokeh
Bokeh is a web‑focused interactive visualization library that can produce D3‑like graphics with relatively low code complexity, but it requires more data‑preparation steps.
from bokeh.transform import dodge
import pandas as pd
from bokeh.io import output_notebook
output_notebook()
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, value df = pd.DataFrame({'商家A': y1, '商家B': y2}, index=x)
_x = ['商家A', '商家B']
data = {'index': x}
for i in _x:
data[i] = df[i].tolist()
source = ColumnDataSource(data=data)
p = figure(x_range=x, y_range=(0,150), plot_height=350, title="bokeh-柱状图",
tools="crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select")
p.vbar(x=dodge('index', -0.1, range=p.x_range), top='商家A', width=0.2, source=source, color="#718dbf", legend=value("商家A"))
p.vbar(x=dodge('index', 0.1, range=p.x_range), top='商家B', width=0.2, source=source, color="#e84d60", legend=value("商家B"))
p.xgrid.grid_line_color = None
p.legend.location = "top_left"
p.legend.orientation = "horizontal"
show(p)Pros: fully interactive, flexible styling. Cons: more code for data handling, scarce Chinese tutorials.
Subjective score: 71 points.
5. Seaborn
Seaborn is a statistical‑visualization library built on top of Matplotlib, offering concise syntax for attractive plots but lacking interactivity.
import seaborn as sns
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']With a single line of code a bar chart can be produced, assuming the data has been converted to a pandas DataFrame.
Pros: minimal code, attractive default palette. Cons: no interactivity, requires DataFrame conversion, limited Chinese resources compared with Matplotlib and Pyecharts.
Subjective score: 72 points.
Conclusion
The five libraries each have distinct strengths: Pyecharts excels in interactivity and documentation; Matplotlib offers flexibility and abundant resources; Plotly and Bokeh provide rich interactive features but have fewer Chinese tutorials; Seaborn delivers concise syntax for statistical plots but lacks interactivity. Choose the tool that matches your scenario, master one, and then explore the others as needed.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
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.
