Last modified: Jun 02, 2026
Plotly Graph Objects Plot Types Guide
Plotly graph objects offer a powerful way to create interactive charts. This guide explains the main plot types you can build. We will use simple examples to show each chart.
You define every element of a plot with graph objects. This approach gives you full control. It is perfect for custom dashboards and reports.
We will focus on the most common plot types. Each section includes code and output. By the end, you will know how to choose the right chart for your data.
Scatter Plots
A scatter plot shows points on a graph. Use go.Scatter to create one. It is great for seeing relationships between two variables.
You can control point size, color, and shape. The mode parameter decides if you show markers, lines, or both.
import plotly.graph_objects as go
# Create a simple scatter plot
fig = go.Figure(data=go.Scatter(
x=[1, 2, 3, 4],
y=[10, 15, 13, 17],
mode='markers+lines', # Show points and lines
marker=dict(size=10, color='blue')
))
fig.show()
# Output: An interactive scatter plot with blue markers and connecting lines.
Scatter plots work well for small to medium datasets. They help spot trends and outliers quickly.
Line Charts
Line charts connect data points with lines. Use go.Scatter with mode set to 'lines'. This is ideal for time series data.
You can add multiple traces to compare trends. Each trace represents a different category or series.
import plotly.graph_objects as go
# Create a line chart with two traces
fig = go.Figure()
fig.add_trace(go.Scatter(
x=[1, 2, 3, 4],
y=[10, 12, 15, 18],
mode='lines',
name='Sales'
))
fig.add_trace(go.Scatter(
x=[1, 2, 3, 4],
y=[8, 9, 11, 14],
mode='lines',
name='Profit'
))
fig.show()
# Output: Two line traces showing sales and profit over time.
Line charts are best for showing changes over time. They make trends easy to see.
Bar Charts
Bar charts display data with rectangular bars. Use go.Bar to create one. Bar charts are perfect for comparing categories.
You can make horizontal or vertical bars. Grouped or stacked bars help compare multiple series.
import plotly.graph_objects as go
# Create a bar chart
fig = go.Figure(data=go.Bar(
x=['Apples', 'Oranges', 'Bananas'],
y=[20, 14, 23],
marker=dict(color='green')
))
fig.show()
# Output: A bar chart with green bars for each fruit category.
Use bar charts for discrete data. They show differences between groups clearly.
Pie Charts
Pie charts show parts of a whole. Use go.Pie to create one. Each slice represents a proportion.
You can customize colors and labels. Pie charts work best with a few categories.
import plotly.graph_objects as go
# Create a pie chart
fig = go.Figure(data=go.Pie(
labels=['Red', 'Blue', 'Green'],
values=[30, 45, 25]
))
fig.show()
# Output: A pie chart with three colored slices showing proportions.
Pie charts are simple and intuitive. Avoid using them for too many categories.
Histograms
Histograms show the distribution of data. Use go.Histogram to create one. They group data into bins.
You can control the number of bins. Histograms reveal the shape of your data distribution.
import plotly.graph_objects as go
# Create a histogram
fig = go.Figure(data=go.Histogram(
x=[1, 2, 2, 3, 3, 3, 4, 4, 5],
nbinsx=5 # Number of bins
))
fig.show()
# Output: A histogram showing frequency of values in five bins.
Histograms help you understand data spread. They are useful for statistical analysis.
Box Plots
Box plots summarize data distribution. Use go.Box to create one. They show median, quartiles, and outliers.
Box plots are great for comparing groups. They reveal variability and skewness.
import plotly.graph_objects as go
# Create a box plot
fig = go.Figure(data=go.Box(
y=[10, 12, 15, 18, 20, 22, 25],
name='Sample Data'
))
fig.show()
# Output: A box plot showing the distribution of sample data.
Box plots are robust for comparing multiple datasets. They highlight outliers effectively.
Heatmaps
Heatmaps show data as a color grid. Use go.Heatmap to create one. They are perfect for correlation matrices.
You can customize the color scale. Heatmaps reveal patterns in large datasets.
import plotly.graph_objects as go
# Create a heatmap
fig = go.Figure(data=go.Heatmap(
z=[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
colorscale='Viridis'
))
fig.show()
# Output: A heatmap with a Viridis color scale showing value intensity.
Heatmaps make complex data visual. They are common in data science and machine learning.
3D Scatter Plots
3D scatter plots show three dimensions. Use go.Scatter3d to create one. They add depth to your analysis.
You can rotate and zoom the plot. 3D plots are excellent for multivariate data exploration.
import plotly.graph_objects as go
# Create a 3D scatter plot
fig = go.Figure(data=go.Scatter3d(
x=[1, 2, 3, 4],
y=[5, 6, 7, 8],
z=[9, 10, 11, 12],
mode='markers',
marker=dict(size=5, color='red')
))
fig.show()
# Output: A 3D scatter plot with red markers in three-dimensional space.
3D plots are engaging but can be confusing. Use them when three variables are equally important.
Combining Plot Types
You can combine multiple plot types in one figure. This creates rich, informative visualizations. For example, add a line trace to a bar chart.
Use fig.add_trace() to mix plot types. This technique is common in financial dashboards.
import plotly.graph_objects as go
# Combine bar and line chart
fig = go.Figure()
fig.add_trace(go.Bar(x=['A', 'B', 'C'], y=[10, 15, 12], name='Sales'))
fig.add_trace(go.Scatter(x=['A', 'B', 'C'], y=[8, 11, 9], mode='lines+markers', name='Profit'))
fig.show()
# Output: A combined chart with bars for sales and a line for profit.
Combining charts helps compare different metrics. It makes your story more compelling.
Customizing Layout
Layout controls the chart appearance. Use fig.update_layout() to set titles, axes, and colors. A clean layout improves readability.
You can also add annotations and shapes. Customization is key for professional reports.
import plotly.graph_objects as go
# Customize layout
fig = go.Figure(data=go.Scatter(x=[1, 2, 3], y=[4, 5, 6]))
fig.update_layout(
title='Custom Scatter Plot',
xaxis_title='X Axis',
yaxis_title='Y Axis',
template='plotly_dark'
)
fig.show()
# Output: A scatter plot with a title and dark theme.
Always customize your layout. It makes your charts look polished and professional.
Conclusion
Plotly graph objects give you complete control over your charts. You learned about scatter, line, bar, pie, histogram, box, heatmap, and 3D plots. Each type serves a specific purpose.
Start with simple plots and add complexity as needed. Practice with real data to build confidence. For deeper exploration, check out the Python Plotly Graph Objects Visualization Guide.
Remember to choose the right plot type for your data. Use customization to make your charts clear. With these skills, you can create stunning interactive visualizations.
For more advanced techniques, revisit the Python Plotly Graph Objects Visualization Guide. It covers layouts, animations, and more.