
I’ve recently started learning Python, and one of the first libraries that caught my attention was Seaborn. Built on top of Matplotlib, Seaborn takes the heavy lifting out of chart creation by offering a simpler, high‑level interface that makes visualizations look polished with minimal effort.
Matplotlib is Python’s core plotting library, giving you full control to customize every detail of a chart. It’s perfect when you need precision and flexibility. Seaborn, on the other hand, is designed to work seamlessly with Pandas DataFrames, which means you can turn structured datasets into clear, attractive charts in just a few lines of code. Both libraries are open‑source and freely available, making them excellent choices for anyone working with data. The difference lies in how you use them:
· Matplotlib is best for highly customized, detailed visualizations.
· Seaborn is best for quick, clean statistical graphics with minimal formatting hassle.
What I love most about Seaborn is how quickly you can go from raw data to polished visuals without wrestling with complex syntax.
In this post, I’ll show you a simple example of using Seaborn to build a stock price tracker that visualizes data for selected tickers over different time periods.
Step 1: Downloading Market Data with yfinance
Created by Ran Aroussi, yfinance has quickly become one of the most popular Python libraries for retrieving financial data directly from Yahoo Finance. Yahoo Finance itself is a comprehensive platform, offering insights into equities, bonds, foreign exchange, and even digital assets such as cryptocurrencies. Beyond raw pricing data, it also provides access to news, expert analysis, detailed reports, options data, and company fundamentals—giving it a distinct advantage over many other financial data sources.
Here’s a simple example of how to fetch market data using yfinance:
import yfinance as yf
def fetch_data(tickers="AAPL", period="6mo"):
data = yf.download(tickers, period=period)["Close"].reset_index()
return data
yf.download(tickers, period=period)["Close"].reset_index() – fetches closing prices for given tickers over a time period and returns a clean DataFrame with Date and Close columns ready for plotting.
If you pass more than one ticker, e.g. "AAPL MSFT", the output will have multiple columns as below
| Date | AAPL | MSFT |
|---|---|---|
| 2025-06-01 | 182.45 | 320.10 |
| 2025-06-02 | 183.10 | 322.50 |
| 2025-06-03 | 180.75 | 319.80 |
| 2025-06-04 | 185.20 | 325.40 |
| 2025-06-05 | 186.05 | 327.15 |
Step 2 : Plotting with Seaborn and Matplotlib
Once we have the data, we use Seaborn and Matplotlib to create a multi-line chart showing price trends over time, as below:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
def plot_data(data, tickers, style="whitegrid"):
prices = pd.melt(
data,
id_vars=["Date"],
value_vars=tickers,
var_name="Ticker",
value_name="Price"
)
sns.set_style(style)
sns_plot = sns.lineplot(x="Date", y="Price", hue="Ticker", data=prices)
sns_plot.set_title("Stock Prices")
sns_plot.set_xlabel("Date")
sns_plot.set_ylabel("Price (USD)")
sns_plot.legend(title="Ticker")
plt.tight_layout()
plt.show()
This function leverages Pandas, Seaborn, and Matplotlib to transform raw stock price data into a clean, easy‑to‑read line chart. Lets go through it line by line.
- Reshaping data
prices = pd.melt(
data,
id_vars=["Date"],
value_vars=tickers,
var_name="Ticker",
value_name="Price"
)
pd.melt() is a Pandas function that reshapes a DataFrame from wide format to long format, making it easier to work with tools like Seaborn for plotting. This structure makes it straightforward for Seaborn to plot multiple tickers on the same chart.
- Setting the Style
sns.set_style(style)
Applies a visual theme (e.g., “whitegrid“, “darkgrid“) to the plot.
- Creating the Line Plot
sns_plot = sns.lineplot(x="Date", y="Price", hue="Ticker", data=prices)
Draws a line chart with Date on the x‑axis and Price on the y‑axis. The hue=”Ticker” argument ensures each company’s stock price is displayed in a distinct color.
- Customizing Labels and Title
sns_plot.set_title("Stock Prices")
sns_plot.set_xlabel("Date")
sns_plot.set_ylabel("Price (USD)")
sns_plot.legend(title="Ticker")
- Show the plot
plt.tight_layout()
plt.show()
tight_layout() adjusts spacing so labels don’t overlap, and show() displays the finished chart.
If you’d like to try out the code from this post or explore the full project, you can find it here
Once you run the code, you get the below chart rendered in a separate window

Conclusion
Whether you’re tracking markets, analyzing datasets, or simply experimenting with charts, these tools give you the flexibility to start simple and grow into more advanced projects. I hope this example inspires you to try building your own visualizations — once you see your first chart come to life, you’ll realize how fun and rewarding data visualization in Python can be.

Leave a comment