![]() |
VOOZH | about |
Strong libraries like Matplotlib, Seaborn, Plotly, and Bokeh serve as the foundation of Pythonβs data visualization ecosystem. Together, they provide a wide range of tools for trend analysis, results presentation, and the creation of dynamic dashboards. Python Libraries for Data Visualization offer broad customization choices, interactive capabilities, and reliable features that connect smoothly with other data processing tools. In this article, we investigate the best Python packages for data visualization, looking at their special advantages, adaptable features, and practical uses.
Here are seven popular data visualization libraries in Python:
An effective tool for making static, animated, and interactive visualizations in Python is the Matplotlib module. With GUI toolkits such as Tkinter, wxPython, Qt, or GTK, it provides an object-oriented API for embedding plots into applications. Matplotlib is versatile and supports a large range of plot types, making it appropriate for both simple and intricate representations. Robust libraries such as Matplotlib, Seaborn, Plotly, and Bokeh offer tools for dynamic dashboards, data trend analysis, and presentation.
plt.plot(x, y, label='Line Plot')plt.scatter(x, y, label='Scatter Plot')plt.bar(categories, values, label='Bar Chart')plt.hist(data, bins=10, label='Histogram')plt.imshow(image_data, cmap='gray')plt.show()plt.subplot(2, 1, 1) or fig, ax = plt.subplots(nrows=2, ncols=1)plt.title('Plot Title')plt.xlabel('X Axis Label'), plt.ylabel('Y Axis Label')plt.legend()plt.savefig('plot.png')plt.grid(True)plt.imshow(data, cmap='custom_cmap')plt.annotate('Annotation Text', xy=(x, y), xytext=(x2, y2), arrowprops=dict(facecolor='black', shrink=0.05))ax = plt.axes(projection='3d'); ax.plot3D(x, y, z, 'gray')import matplotlib.pyplot as plt
import numpy as np
# Line Plot
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y, label='Sine Wave')
plt.title('Sine Wave Example')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.legend()
plt.grid(True)
plt.show()
# Scatter Plot
x = np.random.rand(50)
y = np.random.rand(50)
plt.scatter(x, y, label='Scatter Points')
plt.title('Scatter Plot Example')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.legend()
plt.grid(True)
plt.show()
Designed to make it simpler to generate visually appealing and educational statistical visualizations, Seaborn is a Python visualization framework built on top of Matplotlib. Plotting is made easier and the final results look better thanks to its high-level interface for creating intricate and visually appealing visualizations. Seaborn is an effective tool for exploratory data analysis and visual storytelling because it comes with pre-installed themes and color schemes.
sns.heatmap(data, annot=True, cmap='viridis')sns.boxplot(x='category', y='value', data=df)sns.violinplot(x='category', y='value', data=df)sns.pairplot(df)sns.distplot(data, kde=True)sns.catplot(x='category', y='value', data=df, kind='box')sns.jointplot(x='variable1', y='variable2', data=df, kind='scatter')sns.lmplot(x='variable1', y='variable2', data=df)sns.countplot(x='category', data=df)g = sns.FacetGrid(df, col='category'); g.map(sns.histplot, 'value')sns.set_theme(style='whitegrid')sns.set_palette('pastel')sns.set_context('notebook', font_scale=1.5)import seaborn as sns
import pandas as pd
import numpy as np
# Sample data
df = pd.DataFrame({
'category': np.random.choice(['A', 'B', 'C'], size=100),
'value': np.random.randn(100)
})
# Box Plot
sns.boxplot(x='category', y='value', data=df)
sns.set_theme(style='whitegrid')
sns.despine()
plt.title('Box Plot Example')
plt.show()
# Pair Plot
iris = sns.load_dataset('iris')
sns.pairplot(iris, hue='species')
plt.title('Pair Plot Example')
plt.show()
# Heatmap
data = np.random.rand(10, 12)
sns.heatmap(data, annot=True, fmt=".1f", cmap='coolwarm')
plt.title('Heatmap Example')
plt.show()
Plotly is a feature-rich interactive graphing library that supports a wide variety of charts and visualizations. Plotlyβs interactive features and ease of integration with online apps make it a popular tool for creating dynamic, web-based infographics. It uses the D3.js framework as its foundation and provides a Python interface that makes it easy to create complex visualizations with little to no coding. Plotly features built-in support for Jupyter Notebooks, making it a handy tool for data exploration and analysis.
fig = px.scatter(df, x='x', y='y', color='category')fig = px.line(df, x='x', y='y', color='category')fig = px.bar(df, x='x', y='y', color='category')fig = px.histogram(df, x='x', nbins=20)fig = px.imshow(data, color_continuous_scale='Viridis')fig = px.pie(df, names='category', values='values')fig = px.box(df, x='category', y='value')fig = px.violin(df, x='category', y='value')fig = px.choropleth(df, locations='iso_alpha', color='value', hover_name='country')fig = px.scatter_3d(df, x='x', y='y', z='z', color='category')fig = px.scatter(df, x='x', y='y', facet_col='category')fig.update_layout(title='Plot Title', xaxis_title='X Axis', yaxis_title='Y Axis')fig.add_annotation(x=x, y=y, text='Annotation Text')fig.update_traces(marker=dict(size=10, symbol='circle'), line=dict(width=2))import plotly.express as px
import pandas as pd
# Sample data
df = pd.DataFrame({
'x': range(10),
'y': [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],
'category': ['A', 'A', 'B', 'B', 'A', 'A', 'B', 'B', 'A', 'B']
})
# Scatter Plot
fig = px.scatter(df, x='x', y='y', color='category', title='Scatter Plot Example')
fig.show()
# Line Plot
fig = px.line(df, x='x', y='y', color='category', title='Line Plot Example')
fig.show()
# Bar Chart
fig = px.bar(df, x='x', y='y', color='category', title='Bar Chart Example')
fig.show()
# Histogram
fig = px.histogram(df, x='y', nbins=5, title='Histogram Example')
fig.show()
# Heatmap
data = [[1, 20, 30], [20, 1, 60], [30, 60, 1]]
fig = px.imshow(data, text_auto=True, color_continuous_scale='Viridis', title='Heatmap Example')
fig.show()
Bokeh is a Python library designed for creating interactive visualizations for modern web browsers. It provides elegant and concise construction of versatile graphics and delivers high-performance interactivity over large datasets. Bokeh is particularly useful for creating complex and dynamic visualizations that can be easily integrated into web applications. It supports a variety of plot types and interactive features, making it a powerful tool for data visualization in web-based environments
p = figure(title="My Plot", x_axis_label='X', y_axis_label='Y')p.line(x, y, legend_label="Line", line_width=2)p.scatter(x, y, size=10, color="navy", alpha=0.5)p.vbar(x=categories, top=values, width=0.5)show(p)source = ColumnDataSource(data=dict(x=x, y=y))slider = Slider(start=0, end=10, value=1, step=0.1, title="Slider")p.circle(x, y, size=15, color="firebrick", alpha=0.6)p.add_tools(HoverTool(tooltips=[("x", "@x"), ("y", "@y")]))layout = column(p, slider)from bokeh.plotting import figure, show, output_notebook
# Enable output in the notebook
output_notebook()
# Sample data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
# Create a new plot with a title and axis labels
p = figure(title="Line Plot Example", x_axis_label='X', y_axis_label='Y')
# Add a line renderer with legend and line thickness
p.line(x, y, legend_label="Temp.", line_width=2)
# Show the results
show(p)
Altair is a declarative statistical visualization library for Python, based on the Vega and Vega-Lite visualization grammars. It is designed for simplicity and efficiency in creating complex statistical plots. Altair allows users to define visualizations in a concise and human-readable syntax, making it easy to generate a wide range of visual representations of data. By leveraging the power of Vega and Vega-Lite, Altair can handle complex data transformations and interactive features seamlessly.
chart = alt.Chart(data)chart.mark_point(), chart.mark_bar()encode method specifies how data columns should be represented in the chart.chart.encode(x='column1', y='column2')chart.transform_filter('datum.column > value'), chart.transform_aggregate(mean_value='mean(column)')chart.interactive()chart1 + chart2chart.facet('column')alt.hconcat(chart1, chart2), alt.vconcat(chart1, chart2)alt.themes.enable('dark')import pandas as pd
import altair as alt
source = pd.DataFrame({
"Day": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
"Value": [55, 112, 65, 38, 80, 138, 120, 103, 395, 200, 72, 51, 112, 175, 131]
})
threshold = 300
bars = alt.Chart(source).mark_bar(color="steelblue").encode(
x="Day:O",
y="Value:Q",
)
highlight = bars.mark_bar(color="#e45755").encode(
y2=alt.Y2(datum=threshold)
).transform_filter(
alt.datum.Value > threshold
)
rule = alt.Chart().mark_rule().encode(
y=alt.Y(datum=threshold)
)
label = rule.mark_text(
x="width",
dx=-2,
align="right",
baseline="bottom",
text="hazardous"
)
(bars + highlight + rule + label)
ggplot is a Python implementation of the grammar of graphics, based on the well-known ggplot2 library in R. It allows users to create complex and multi-layered visualizations using a consistent grammar. This approach provides a structured and intuitive way to build visualizations by specifying different layers of the plot and their aesthetic mappings.
ggplot(data)aes(x='column1', y='column2', color='column3')geom_point(), geom_line(), geom_bar(), geom_histogram(), etc.stat_smooth(), stat_bin(), stat_summary()facet_wrap(), facet_grid()theme_bw(), theme_minimal(), theme_void()labs(title='Title', x='X Axis', y='Y Axis')from plotnine import ggplot, aes, geom_point
import pandas as pd
data = pd.DataFrame({
'x': range(10),
'y': range(10)
})
plot = (ggplot(data, aes('x', 'y')) +
geom_point())
print(plot)
Holoviews is a high-level library for creating complex visualizations easily and quickly. It allows you to work with data structures directly and focuses on enabling interactive visualizations with minimal code. Holoviews is designed to handle large datasets efficiently and integrates seamlessly with other visualization libraries like Bokeh and Matplotlib.
hv.Curve(data)hv.Points(data)hv.Image(array)hv.HoloMap({key: object})hv.Bars(data)hv.HeatMap(data)hv.Dataset(data)hv.Overlay([element1, element2, ...])import numpy as np
import holoviews as hv
# Sample data
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Create a curve plot
curve = hv.Curve((x, y), 'X-axis', 'Y-axis')
# Display the plot using Jupyter notebook integration
hv.extension('bokeh') # Use the Bokeh backend for plotting
curve
Python libraries for data visualization offer versatile tools for creating visually appealing graphics. Matplotlib, Seaborn, Plotly, Bokeh, Altair, and ggplot are popular for web-based applications and dynamic visualizations. Holoviews, capable of handling large datasets and producing interactive visualizations with minimal code, is particularly useful for large datasets. These libraries ensure Python remains a dominant force in data visualization, enabling users to effectively communicate insights and discoveries.
You can also enroll in our free Python course today!
My name is Ayushi Trivedi. I am a B. Tech graduate. I have 3 years of experience working as an educator and content editor. I have worked with various python libraries, like numpy, pandas, seaborn, matplotlib, scikit, imblearn, linear regression and many more. I am also an author. My first book named #turning25 has been published and is available on amazon and flipkart. Here, I am technical content editor at Analytics Vidhya. I feel proud and happy to be AVian. I have a great team to work with. I love building the bridge between the technology and the learner.
GPT-4 vs. Llama 3.1 β Which Model is Better?
Llama-3.1-Storm-8B: The 8B LLM Powerhouse Surpa...
A Comprehensive Guide to Building Agentic RAG S...
Top 10 Machine Learning Algorithms in 2026
45 Questions to Test a Data Scientist on Basics...
90+ Python Interview Questions and Answers (202...
8 Easy Ways to Access ChatGPT for Free
Prompt Engineering: Definition, Examples, Tips ...
What is LangChain?
What is Retrieval-Augmented Generation (RAG)?
Edit
Resend OTP
Resend OTP in 45s