Fundamentals 8 min read

Python Visualization Libraries: Matplotlib, Seaborn, Plotly, Bokeh, Altair, Plotnine, VisPy, Pygame, Kivy, PyQt/PySide – Code Samples and Usage

This article introduces ten popular Python visualization and GUI libraries—Matplotlib, Seaborn, Plotly, Bokeh, Altair, Plotnine, VisPy, Pygame, Kivy, and PyQt/PySide—providing concise code examples and brief explanations of their typical use cases and strengths.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Python Visualization Libraries: Matplotlib, Seaborn, Plotly, Bokeh, Altair, Plotnine, VisPy, Pygame, Kivy, PyQt/PySide – Code Samples and Usage

Matplotlib

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi, 400)
y = np.sin(x**2)
plt.figure(figsize=(8, 6))
plt.plot(x, y)
plt.title('Beautiful Sine Wave')
plt.xlabel('X-Axis')
plt.ylabel('Y-Axis')
plt.show()

Matplotlib is one of the most widely used Python plotting libraries, capable of generating static, animated, and interactive visualizations and supporting multiple output formats such as PDF, SVG, and PNG.

Seaborn

import seaborn as sns
import pandas as pd
tips = sns.load_dataset("tips")
sns.relplot(data=tips, x="total_bill", y="tip", hue="smoker",
    size="size", col="day", row="time",
    palette="viridis", height=4, aspect=.75)

Seaborn builds on Matplotlib to provide a higher‑level API and attractive default styles, making statistical graphics more beautiful and intuitive.

Plotly

import plotly.graph_objs as go
fig = go.Figure(data=[go.Scatter(
    x=[1, 2, 3, 4],
    y=[10, 15, 13, 17]
)])
fig.show()

Plotly is a powerful JavaScript‑based visualization library with a Python wrapper that enables creation of interactive, web‑ready charts and integration with Dash applications.

Bokeh

from bokeh.plotting import figure, show, output_file
from bokeh.models import HoverTool
output_file("toolbar.html")
TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select,lasso_select"
p = figure(tools=TOOLS)
p.circle([1, 2, 3, 4], [4, 5, 1, 2], size=15, line_color="navy", fill_color="orange", fill_alpha=0.5)
show(p)

Bokeh specializes in creating interactive visualizations for large datasets, offering high performance and scalability.

Altair

import altair as alt
source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})
alt.Chart(source).mark_bar().encode(
    x='a',
    y='b'
)

Altair is a declarative Python library based on the Vega‑Lite grammar, allowing concise creation of interactive visualizations with multiple output options.

Plotnine

from plotnine import ggplot, aes, geom_line, facet_wrap, theme_bw
df = pd.read_csv('https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/ggplot2/diamonds.csv')
(ggplot(df, aes(x='carat', y='price'))
 + geom_line()
 + facet_wrap('~cut')
 + theme_bw())

Plotnine brings the grammar of R’s ggplot2 to Python, offering a “grammar of graphics” approach that simplifies the construction of complex plots.

VisPy

from vispy import scene, io
canvas = scene.SceneCanvas(keys='interactive', show=True)
view = canvas.central_widget.add_view()
image = scene.visuals.Image(io.load_image('your-image-file.jpg'), parent=view.scene)
rect = scene.visuals.Rectangle(color='red', width=200, height=100,
    pos=(100, 100), border_width=5,
    parent=view.scene)
view.camera.set_range((0, 200), (0, 200))

VisPy is a high‑performance, cross‑platform visualization library designed for large data sets and real‑time applications, leveraging hardware acceleration.

Pygame

import pygame
pygame.init()
win = pygame.display.set_mode((500, 500))
run = True
while run:
    pygame.time.delay(100)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    win.fill((255, 255, 255))
    pygame.draw.rect(win, (0, 0, 255), (50, 50, 100, 100))
    pygame.display.update()
pygame.quit()

Pygame is a Python library for game development that provides multimedia handling (graphics, sound, video) and is suitable for creating desktop games or interactive visualizations.

Kivy

from kivy.app import App
from kivy.uix.button import Button
class MyApp(App):
    def build(self):
        return Button(text='Hello World')
if __name__ == '__main__':
    MyApp().run()

Kivy is an open‑source Python framework for building natural user interfaces, supporting multi‑touch applications across Windows, Linux, macOS, and Android.

PyQt / PySide

import sys
from PyQt5.QtWidgets import QApplication, QLabel
app = QApplication(sys.argv)
label = QLabel('Hello World!')
label.show()
sys.exit(app.exec_())

PyQt and PySide are Python bindings for the Qt framework, enabling the creation of sophisticated desktop GUI applications with rich visual components.

PythonData VisualizationMatplotlibPlotlyseabornBokehPygame
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.