Matplotlib and Seaborn: Plotting for Analysts
SkillVeris Team
Engineering Team

You will understand how Matplotlib's figure and axes objects give you full control over every chart element.
In this guide, you'll learn:
- You will know when to reach for Seaborn's high-level functions instead of writing Matplotlib code by hand.
- You will be able to pick the right chart type for distributions, comparisons, relationships, and time series.
- You will learn to label, annotate, and style figures so they read clearly without a caption.
- You will avoid the common mistakes that make charts misleading, cluttered, or hard to read.
1Matplotlib and Seaborn for Analysts
Matplotlib and Seaborn are the two Python libraries most analysts use to turn data into charts. Matplotlib is the low-level engine that draws every pixel and gives you total control, while Seaborn sits on top of it to produce attractive statistical graphics with far less code. Used together, they take you from a quick exploratory plot to a polished, publication-ready figure.
If you already work with pandas, you are most of the way there: both libraries plot directly from DataFrames and Series. The goal of this guide is not to memorize every function but to build a mental model — figure out what you want to show, choose the chart that shows it honestly, and then refine until it reads clearly on its own.
By the end you will know which library to reach for in a given situation, how to control layout and styling, and how to export figures that look sharp in a report or on screen.
2How Matplotlib and Seaborn Fit Together
Think of Matplotlib as the canvas and toolbox, and Seaborn as a set of pre-designed templates that draw on that canvas. Because Seaborn is built on Matplotlib, any Seaborn chart is still a Matplotlib figure underneath, so you can always drop down to Matplotlib to tweak a title, axis, or color after Seaborn has done the heavy lifting.
The practical rule: use Seaborn when your goal is a standard statistical chart from a tidy DataFrame — a histogram, box plot, scatter with a regression line, or a grouped bar chart. Reach for raw Matplotlib when you need a custom layout, an unusual chart, or fine control that no high-level function offers.
- Matplotlib: maximum control, more verbose, great for custom and composite figures.
- Seaborn: concise, attractive defaults, statistical charts straight from DataFrames.
- You can — and often should — mix them in the same script.
3The Figure and Axes Model
The single most useful thing to understand in Matplotlib is the difference between a Figure and an Axes. The Figure is the whole image — the outer container. An Axes is one plot inside it, with its own x and y coordinates. A figure can hold several axes arranged in a grid, which is how you build multi-panel charts.
The clearest way to work is the object-oriented style: create both explicitly with fig, ax = plt.subplots(), then call methods on the ax object such as ax.plot(), ax.set_title(), and ax.set_xlabel(). This is more predictable than the older plt.plot() shortcut, especially once you have more than one panel. Seaborn functions accept an ax= argument, so you can direct each Seaborn chart to a specific panel in your grid.
💡Prefer the object-oriented style
Writing fig, ax = plt.subplots() and then styling ax explicitly scales far better than the plt.* shortcuts. When you later add a second panel, nothing breaks because every command already targets a named axes.
4Choosing the Right Chart
A chart's job is to answer a specific question, so pick the type from the question you are asking, not from what looks impressive. Getting this right matters more than styling.
Match the analytical intent to the visual form and your audience will read the answer almost instantly.
- Distribution of one variable: histogram, KDE, or box/violin plot.
- Comparison across categories: bar chart, grouped bar, or point plot.
- Relationship between two numbers: scatter plot, optionally with a trend line.
- Change over time: line chart.
- Composition of a whole: stacked bar (avoid pie charts for more than a few slices).
5Your First Charts
A basic line chart in Matplotlib is three lines: create the axes, call ax.plot(x, y), and add labels with ax.set_xlabel() and ax.set_ylabel(). A bar chart swaps in ax.bar(categories, values). These primitives cover a surprising amount of everyday work.
Seaborn compresses common patterns further. sns.histplot(data=df, x='age') draws a histogram with sensible bins; sns.scatterplot(data=df, x='height', y='weight', hue='group') colors points by a category automatically; sns.barplot(data=df, x='team', y='score') computes and plots the mean per group with a confidence interval. Passing hue, col, or row lets you split one chart into many by category with almost no extra code.
6Visualizing Distributions
Before comparing groups, understand the shape of each variable. A histogram bins values into ranges and counts them, showing skew, spread, and outliers at a glance. Seaborn's histplot can overlay a smooth kernel density estimate (KDE) with kde=True, which helps when bin edges feel arbitrary.
Box plots and violin plots shine when you compare a distribution across categories. A box plot summarizes the median, quartiles, and outliers; a violin plot adds the full density shape so you can see whether a group is bimodal. Use sns.boxplot or sns.violinplot with x as the category and y as the numeric value.
7Showing Relationships
Scatter plots reveal how two numeric variables move together. Add a regression line with sns.regplot or sns.lmplot to see the trend and its uncertainty band. When you have several numeric columns, sns.pairplot draws a grid of scatter plots for every pair plus histograms on the diagonal — a fast way to spot correlations before formal modeling.
For dense data where points overlap, a scatter can turn into an unreadable blob. Reduce the alpha (transparency) so overlapping points darken, or switch to a hexbin or 2D density plot that bins points into cells and colors by count.
8Styling and Readable Figures
Good styling is mostly about removing clutter and adding context. Give every figure a descriptive title, label both axes with units, and include a legend only when color or shape encodes a variable. Seaborn's sns.set_theme() applies clean defaults, and styles like 'whitegrid' add subtle gridlines that help readers estimate values.
Color is a tool, not decoration. Use a sequential palette for ordered data, a diverging palette when a midpoint matters, and a categorical palette for unordered groups. Keep the number of colors small, and check that your choices stay distinguishable for colorblind readers — Seaborn's 'colorblind' palette is a safe default.
⚠️Do not let the axis mislead
Truncating a bar chart's y-axis so it does not start at zero exaggerates small differences. For bars, start at zero. For line charts of tightly ranged data, a non-zero baseline can be acceptable — but label it clearly.
9Multi-Panel and Annotated Figures
Real reports often need several related charts side by side. plt.subplots(nrows=2, ncols=2) returns a grid of axes you can fill individually, and fig.tight_layout() spaces them so labels do not collide. Seaborn's FacetGrid and the col/row arguments automate this when you are splitting one dataset by category.
Annotations turn a chart into an argument. Use ax.annotate() to point at a peak, ax.axhline() to mark a target or average, and ax.text() to label an important point directly rather than forcing the reader to consult a legend. A single well-placed annotation often communicates more than an extra paragraph of caption.
10Exporting Publication-Ready Figures
Save figures with fig.savefig('chart.png', dpi=300, bbox_inches='tight'). The dpi setting controls resolution — 300 is crisp for print and slides — and bbox_inches='tight' trims excess whitespace. For web or documents that scale, export to SVG or PDF, which are vector formats that stay sharp at any size.
Set the figure size early with plt.subplots(figsize=(width, height)) in inches so text and elements are proportioned correctly when saved. Resizing a finished raster image afterward blurs it; sizing the figure up front keeps everything sharp.
11Frequently Asked Questions
Do I need both Matplotlib and Seaborn? Not always, but they complement each other. Seaborn gets you a clean statistical chart in one line, and Matplotlib lets you fine-tune it afterward — most analysts use them together.
Is Seaborn faster to learn than Matplotlib? For common charts, yes. Seaborn's high-level functions handle grouping, coloring, and statistics automatically, so beginners often start there and learn Matplotlib's details as they need more control.
Can I plot directly from a pandas DataFrame? Yes. pandas has a built-in .plot() method backed by Matplotlib, and both Seaborn and Matplotlib accept DataFrame columns directly, so you rarely need to convert your data first.
How do I make my charts look professional? Add clear titles and axis labels with units, remove chart junk, use a restrained color palette, and export at high resolution. Consistency across a report matters more than any single flourish.
Which chart type should I use for my data? Match the chart to the question: distributions use histograms or box plots, comparisons use bar charts, relationships use scatter plots, and trends over time use line charts.
Is Matplotlib still relevant in 2026? Absolutely. It remains the foundation of the Python plotting ecosystem, and most other libraries — including Seaborn and pandas plotting — are built on top of it.
12Next Steps
You now have a working map of Python plotting: Matplotlib for control, Seaborn for speed, and a decision process that starts from the question you are answering. The fastest way to improve is to recreate a chart you admire and then rebuild it from your own data, refining labels, color, and layout until it reads cleanly on its own.
You can practice all of this for free on SkillVeris, where the Python and data analysis courses walk through pandas, Matplotlib, and Seaborn with hands-on datasets. Pair this article with the study notes on data visualization and statistics to turn plotting from a chore into a genuine analytical skill.
Related Reading
Get The Print Version
Download a PDF of this article for offline reading.
About the Publisher
SkillVeris Team
Engineering Team
Our engineering writers turn abstract code concepts into hands-on, project-driven learning experiences.
View all postsRelated Posts
Never miss an update
Get the latest tutorials and guides delivered to your inbox.
No spam. Unsubscribe anytime.