An open-source interactive data visualization library for Python
npx @tessl/cli install tessl/pypi-plotly@6.3.0An open-source interactive data visualization library for Python that enables developers to create interactive, browser-based graphs and charts. Built on top of plotly.js, it offers over 30 chart types including scientific charts, 3D graphs, statistical charts, SVG maps, and financial charts with declarative, high-level APIs.
pip install plotlyimport plotlyHigh-level plotting interface:
import plotly.express as pxLow-level graph objects:
import plotly.graph_objects as goFigure factory for specialized charts:
import plotly.figure_factory as ffI/O operations:
import plotly.io as pioSubplot and utility functions:
import plotly.tools as toolsimport plotly.express as px
import pandas as pd
# Create sample data
df = pd.DataFrame({
'x': [1, 2, 3, 4, 5],
'y': [2, 4, 3, 5, 6],
'category': ['A', 'B', 'A', 'B', 'A']
})
# Create a simple scatter plot
fig = px.scatter(df, x='x', y='y', color='category',
title='Interactive Scatter Plot')
fig.show()
# Create a line chart with graph objects
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1, 2, 3, 4], y=[10, 11, 12, 13], mode='lines+markers'))
fig.update_layout(title='Line Chart with Graph Objects')
fig.show()Plotly provides multiple levels of abstraction for creating visualizations:
The library integrates seamlessly with Jupyter notebooks, supports both online and offline rendering, and provides extensive customization options for publication-quality visualizations.
High-level plotting functions for rapid visualization creation with over 40 chart types including scatter, line, bar, histogram, box plots, geographic maps, 3D plots, and statistical charts.
def scatter(data_frame, x=None, y=None, color=None, size=None, **kwargs): ...
def line(data_frame, x=None, y=None, color=None, **kwargs): ...
def bar(data_frame, x=None, y=None, color=None, **kwargs): ...
def histogram(data_frame, x=None, y=None, color=None, **kwargs): ...
def box(data_frame, x=None, y=None, color=None, **kwargs): ...
def scatter_geo(data_frame, lat=None, lon=None, **kwargs): ...
def choropleth(data_frame, locations=None, color=None, **kwargs): ...
def scatter_3d(data_frame, x=None, y=None, z=None, **kwargs): ...Low-level figure construction with complete control over traces, layout, and styling using 50+ trace types and comprehensive layout options.
class Figure:
def __init__(self, data=None, layout=None, **kwargs): ...
def add_trace(self, trace, **kwargs): ...
def update_layout(self, **kwargs): ...
def show(self, **kwargs): ...
class Scatter:
def __init__(self, x=None, y=None, mode=None, **kwargs): ...
class Bar:
def __init__(self, x=None, y=None, **kwargs): ...
class Heatmap:
def __init__(self, z=None, x=None, y=None, **kwargs): ...Specialized figure creation functions for complex statistical and scientific visualizations including annotated heatmaps, dendrograms, distplots, and candlestick charts.
def create_annotated_heatmap(z, x=None, y=None, **kwargs): ...
def create_dendrogram(X, **kwargs): ...
def create_distplot(hist_data, group_labels, **kwargs): ...
def create_candlestick(open, high, low, close, dates, **kwargs): ...
def create_gantt(df, **kwargs): ...Export and import functionality supporting multiple formats including HTML, static images (PNG, JPEG, PDF, SVG), and JSON serialization with Kaleido engine integration.
def show(fig, **kwargs): ...
def write_html(fig, file, **kwargs): ...
def write_image(fig, file, format=None, **kwargs): ...
def write_json(fig, file, **kwargs): ...
def read_json(file): ...
def to_html(fig, **kwargs): ...
def to_image(fig, format=None, **kwargs): ...Comprehensive color management with built-in color scales, palette generation, and color format conversion supporting sequential, diverging, cyclical, and qualitative color schemes.
def hex_to_rgb(hex_color): ...
def rgb_to_hex(rgb_tuple): ...
def make_colorscale(colors, **kwargs): ...
def sample_colorscale(colorscale, samplepoints, **kwargs): ...
# Color scale namespaces
sequential: ... # Viridis, Plasma, Blues, etc.
diverging: ... # RdBu, RdYlBu, Spectral, etc.
qualitative: ... # Set1, Set2, Pastel1, etc.
cyclical: ... # IceFire, Edge, Phase, etc.Sample datasets for learning and experimentation including iris, tips, gapminder, stocks, and other commonly used datasets in data science.
def iris(): ...
def tips(): ...
def gapminder(): ...
def stocks(): ...
def flights(): ...
def election(): ...Tools for creating subplot layouts, converting matplotlib figures, and other utility operations essential for complex figure composition and integration with other plotting libraries.
def make_subplots(rows=1, cols=1, subplot_titles=None, **kwargs): ...
def get_subplots(rows=1, columns=1, **kwargs): ...
def mpl_to_plotly(fig, resize=False, **kwargs): ...
def get_config_plotly_server_url(): ...# Core figure type returned by all plotting functions
class Figure:
data: tuple # Traces
layout: dict # Layout configuration
def show(self, **kwargs): ...
def update_layout(self, **kwargs): ...
def add_trace(self, trace, **kwargs): ...
def write_html(self, file, **kwargs): ...
def write_image(self, file, **kwargs): ...
# Widget version for Jupyter notebooks
class FigureWidget(Figure):
def __init__(self, data=None, layout=None, **kwargs): ...