- Python Snacks
- Posts
- Comparing Python Plotting Libraries: Matplotlib, Plotly, Plotext
Comparing Python Plotting Libraries: Matplotlib, Plotly, Plotext
Here's how you can pick the right tool for the job
Being able to visualize your data is essential to the data analysis process. If you ask me, you don’t have a true understanding of your data if you don’t know how to visualize your data.
Here, I’m going to highlight 3 visualization packages that have different features and capabilities. Each one I’m going to rate 6 different metrics (on a scale of 1 to 5), show sample code and the graph, and give my 2¢.
Matplotlib
Introduction: Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python, tailored for making professional-quality plots with just a few lines of code (Documentation, GitHub).
My 2¢: Whenever I need to get a visualization to management or coworkers, this is my go-to package. It’s easy to use, intuitive, and has lots of use cases. It’s also the base for other visualization packages such as Seaborn.
My Ratings
Overall: ⭐️⭐️⭐️⭐️⭐️
Ease of Use: ⭐️⭐️⭐️⭐️
Documentation: ⭐️⭐️⭐️⭐️
Performance and Scalability: ⭐️⭐️⭐️
Feature Set and Capabilities: ⭐️⭐️⭐️⭐️⭐️
Regular Updates: ⭐️⭐️⭐️⭐️
Installation and Setup: ⭐️⭐️⭐️⭐️⭐️
Sample code and figure:
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 115, 15
x = mu + sigma * np.random.randn(10000)
fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained')
# Get the
n, bins, patches = ax.hist(x, 50, density=True, facecolor='C0', alpha=0.75)
ax.set_xlabel('Length [cm]')
ax.set_ylabel('Probability')
ax.set_title('Aardvark lengths\n (not really)')
ax.text(75, .025, r'$\mu=115,\ \sigma=15$')
ax.axis([55, 175, 0, 0.03])
ax.grid(True)
plt.show()
Sample matplotlib figure from the code above.
Plotly
Introduction: Plotly is a modern platform for plotting and rendering interactive graphs that can be embedded into web dashboards, offering a high-level interface for data visualization with more aesthetic flexibility (Documentation, GitHub)
My 2¢: As someone who hates writing front-end code, plotly allows me to focus on the visualizations, not the UI. It’s not as straight-forward as Matplotlib, but once you understand how it works it’s super powerful. I wish I learned about this earlier and I had the time to teach myself how to use this!
My Ratings:
Overall: ⭐️⭐️⭐️⭐️
Ease of Use: ⭐️⭐️⭐️
Documentation: ⭐️⭐️⭐️⭐️
Performance and Scalability: ⭐️⭐️⭐️⭐️
Feature Set and Capabilities: ⭐️⭐️⭐️⭐️
Regular Updates: ⭐️⭐️⭐️⭐️
Installation and Setup: ⭐️⭐️⭐️⭐️⭐️
Sample code and figure:
import plotly.graph_objects as go
title = "A Figure Displayed with fig.show()"
fig = go.Figure(
data = [go.Bar(y = [2, 1, 3])],
layout_title_text = title
)
fig.show()
Sample plotly figure from the code above.
Plotext
Introduction: Plotext is designed to bring plotting capabilities to the command-line interface (CLI), allowing users to draw plots directly in the terminal (Documentation, GitHub).
My 2¢: This utility is great for situations where you’re wanting to visualize data in a server that doesn’t necessarily have a web interface associated with it. While I did rate this on the lower end, the niche use of this package is absolutely stellar and I’d recommend this.
My Ratings:
Overall: ⭐️⭐️⭐️⭐️
Ease of Use: ⭐️⭐️⭐️⭐️
Documentation: ⭐️⭐️⭐️
Performance and Scalability: ⭐️⭐️⭐️
Feature Set and Capabilities: ⭐️⭐️⭐️⭐️
Regular Updates: ⭐️⭐️
→ The developer is re-building this from the ground-up as of Feb 1, 2024. PR’s and issues are being reviewed!
Installation and Setup: ⭐️⭐️⭐️⭐️⭐️
Sample code and image:
import plotext as plt
y1 = plt.sin()
y2 = plt.sin(2, phase = -1)
plt.plot(y1, xside = "lower", yside = "left", label = "lower left")
plt.plot(y2, xside = "upper", yside = "right", label = "upper right")
plt.title("Multiple Axes Plot")
plt.show()
Sample plotly figure in terminal from code above
Want even more Python-related content that’s useful? Here’s 3 reasons why you should subscribe the Python Snacks newsletter:
Get Ahead in Python with bite-sized Python tips and tricks delivered straight to your inbox, like the one above.
Exclusive Subscriber Perks: Receive a curated selection of up to 6 high-impact Python resources, tips, and exclusive insights with each email.
Get Smarter with Python in under 5 minutes. Your next Python breakthrough could just an email away.
You can unsubscribe at any time.
Do you have a wealth of knowledge and insights to share with the world? Starting your own newsletter or blog is an excellent way to establish yourself as an authority in your field, connect with a like-minded community, and open up new opportunities.
If TikTok, Twitter, Facebook, or other social media platforms were to get banned, you’d lose all your followers. This is why you should start a newsletter: you own your audience.
This article may contain affiliate links. Affiliate links come at no cost to you and support the costs of this blog. Should you purchase a product/service from an affiliate link, it will come at no additional cost to you.
Reply