Python Data Visualization: Core Steps and Matplotlib Tutorial
This article explains the three essential steps for Python data visualization, introduces key libraries such as Matplotlib, Seaborn, Bokeh and Pandas, and provides detailed examples of creating, customizing, and saving plots with code snippets and practical tips.
In scientific and data‑analysis work, visualizing data with Python follows three core steps: (1) define the problem and choose the appropriate chart type, (2) transform the data and apply the corresponding plotting function, and (3) set parameters to make the chart clear.
The most basic visualization library is Matplotlib , which provides low‑level control over figures and subplots. Higher‑level libraries such as Seaborn (built on Matplotlib) offer concise syntax for multi‑dimensional data, while Bokeh and Mapbox enable interactive and geographic visualizations.
Matplotlib basics include creating a figure, adding subplots, and adjusting size with fig = plt.figure() or fig, axes = plt.subplots(2, 2, sharex=True, sharey=True) . The subplots_adjust function fine‑tunes spacing.
Styling options cover colors, line styles, markers, titles, axis labels, ticks, and legends. Example:
plt.plot(np.random.randn(30), color='g', linestyle='--', marker='o')
Axis limits and ticks are controlled with plt.xlim() , plt.xticks() , and ax.set_xticklabels([...]) . Adding a legend is as simple as passing label='...' to plot calls and invoking ax.legend(loc='best') .
Annotations can be added with plt.text , plt.annotate , or plt.arrow to highlight specific points.
Saving figures uses plt.savefig('filename.png', dpi=300, bbox_inches='tight') , where the file format is inferred from the extension.
Pandas integrates tightly with Matplotlib: both Series.plot() and DataFrame.plot() generate plots with minimal code, supporting line, bar, histogram, and KDE charts via the kind parameter. Bar charts can be created directly with data.plot(kind='bar') or visualized from value counts using df.value_counts().plot(kind='bar') .
Overall, mastering these steps—thinking, choosing, and applying—enables effective and reproducible Python visualizations for research and analytics.
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.