The Beginner’s Guide to Python Visualization Libraries: Making Data Come Alive

Shivani Tanwar
3 min readAug 19, 2023

--

Taken from google.com(Analytics Vidhya)

Welcome aboard the enchanting voyage into the world of Python data visualization!

If you’re just stepping into this realm and feeling like you’re staring at a maze, fret not — we’re here to guide you through. In this beginner’s guide, we’ll introduce you to user-friendly Python visualization libraries. We’ll break down intricate ideas into digestible nuggets, offer hands-on code samples, and sprinkle in simplified diagrams to make your learning journey both engaging and gratifying.

Unveiling the Magic of Data Visualization

Before we roll up our sleeves and dive into the libraries, let’s understand why data visualization is a big deal. Imagine you have a bag of marbles, each representing a number. If you just look at the marbles, you can’t see much. But when you lay them out in patterns, you start to see shapes emerge. Data visualization does that — it turns those marbles (numbers) into beautiful pictures (charts and graphs) that tell you a story.

1. Matplotlib: Your First Toolbox

Meet Matplotlib, your trusty toolbox for creating different types of visualizations. From simple line graphs to intricate plots, Matplotlib has your back.

Starting with Lines

Let’s kick off with a simple example: creating a line graph.

import matplotlib.pyplot as plt #Import matplotlib.pyplot

x = [1, 2, 3, 4, 5] #Make lists x and y for your data.
y = [2, 4, 6, 8, 10]

plt.plot(x, y, marker='o') #Use plt.plot() for a line with markers
plt.xlabel('X-axis') #Label your axes and give your plot a title
plt.ylabel('Y-axis')
plt.title('Simple Line Plot')
plt.show() #Display with plt.show()

Your First Bar Chart

categories = ['Apples', 'Bananas', 'Grapes', 'Oranges']
quantities = [25, 40, 30, 15]

plt.bar(categories, quantities, color='skyblue')
plt.xlabel('Fruits')
plt.ylabel('Quantity')
plt.title('Fruit Quantities')
plt.show()

2. Seaborn: The Stylish Assistant

Seaborn, built on Matplotlib, brings style and simplicity to your visualizations.

Grasping Histograms

import seaborn as sns

data = [20, 15, 30, 25, 40, 10, 5, 30, 25, 15]

sns.histplot(data, bins=5, kde=True, color='purple')
plt.xlabel('Values')
plt.ylabel('Frequency')
plt.title('Histogram with KDE')
plt.show()

3. Plotly: Interactive Adventures

Plotly adds a dash of interactivity to your visualizations, letting you explore data in real-time.

Diving into Scatter Plots

import plotly.express as px

data = {'X': [1, 2, 3, 4, 5],
'Y': [10, 6, 3, 8, 12]}

fig = px.scatter(data, x='X', y='Y', title='Scatter Plot Example')
fig.show()

4. Pandas Plotting: Data-Powered Magic

Pandas, your data buddy, makes creating visualizations from your dataframes a breeze.

Unveiling Area Plots

import pandas as pd

data = {'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
'Revenue': [100, 150, 120, 180, 200]}

df = pd.DataFrame(data)
df.plot(x='Month', y='Revenue', kind='area', color='orange')
plt.xlabel('Month')
plt.ylabel('Revenue')
plt.title('Monthly Revenue Trend')
plt.show()

Your Visualization Adventure Begins

You’re all set for your visualization adventure! We’ve only scratched the surface, but you’re now equipped to turn data into captivating visuals. Remember, practice is your compass. Experiment with different plot types, tweak settings, and watch your data stories come to life. Here’s to your exciting journey of transforming numbers into mesmerizing visuals!

Thanks for Reading!

If you enjoyed this, follow me to never miss another article !

If you have any question feel free to ask!

--

--

No responses yet