CARVIEW |
Select Language
HTTP/2 308
cache-control: public, max-age=0, must-revalidate
content-type: text/plain
date: Tue, 29 Jul 2025 03:26:12 GMT
location: /python/carpet-scatter/
refresh: 0;url=/python/carpet-scatter/
server: Vercel
strict-transport-security: max-age=63072000
x-vercel-id: bom1::vz22g-1753759572985-bce22d2ec973
HTTP/2 200
accept-ranges: bytes
access-control-allow-origin: *
age: 0
cache-control: max-age=600
content-encoding: gzip
content-type: text/html; charset=utf-8
date: Tue, 29 Jul 2025 03:26:13 GMT
etag: W/"687e6266-13af0"
expires: Tue, 29 Jul 2025 03:36:13 GMT
last-modified: Mon, 21 Jul 2025 15:53:10 GMT
server: Vercel
strict-transport-security: max-age=63072000
vary: Accept-Encoding
via: 1.1 varnish
x-cache: MISS
x-cache-hits: 0
x-fastly-request-id: cb6dd796436eb76f9bf872363bd14648ea52658c
x-github-request-id: D0F4:8048C:21DA5:2EF46:68883F54
x-proxy-cache: MISS
x-robots-tag: index
x-served-by: cache-bom-vanm7210085-BOM
x-timer: S1753759573.026233,VS0,VE219
x-vercel-cache: MISS
x-vercel-id: bom1::cj5w8-1753759573009-4c5961d2b8d4
content-length: 11921
Carpet scatter plot in Python
Carpet Scatter Plot in Python
How to make carpet scatter plots in Python with Plotly.
Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Sign up for early access now.
Basic Carpet Plot¶
In [1]:
import plotly.graph_objects as go
fig = go.Figure(go.Carpet(
a = [4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6],
b = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],
y = [2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10],
aaxis = dict(
tickprefix = 'a = ',
ticksuffix = 'm',
smoothing = 1,
minorgridcount = 9
),
baxis = dict(
tickprefix = 'b = ',
ticksuffix = 'Pa',
smoothing = 1,
minorgridcount = 9
)
))
fig.show()
Add Carpet Scatter Trace¶
In [2]:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Carpet(
a = [4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6],
b = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],
y = [2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10],
aaxis = dict(
tickprefix = 'a = ',
ticksuffix = 'm',
smoothing = 1,
minorgridcount = 9
),
baxis = dict(
tickprefix = 'b = ',
ticksuffix = 'Pa',
smoothing = 1,
minorgridcount = 9
)
))
fig.add_trace(go.Scattercarpet(
a = [4, 4.5, 5, 6],
b = [2.5, 2.5, 2.5, 2.5],
line = dict(
shape = 'spline',
smoothing = 1,
color = 'blue'
)
))
fig.show()
Add Multiple Scatter Traces¶
In [3]:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Carpet(
a = [0.1,0.2,0.3],
b = [1,2,3],
y = [[1,2.2,3],[1.5,2.7,3.5],[1.7,2.9,3.7]],
cheaterslope = 1,
aaxis = dict(
title = "a",
tickmode = "linear",
dtick = 0.05
),
baxis = dict(
title = "b",
tickmode = "linear",
dtick = 0.05
)
))
fig.add_trace(go.Scattercarpet(
name = "b = 1.5",
a = [0.05, 0.15, 0.25, 0.35],
b = [1.5, 1.5, 1.5, 1.5]
))
fig.add_trace(go.Scattercarpet(
name = "b = 2",
a = [0.05, 0.15, 0.25, 0.35],
b = [2, 2, 2, 2]
))
fig.add_trace(go.Scattercarpet(
name = "b = 2.5",
a = [0.05, 0.15, 0.25, 0.35],
b = [2.5, 2.5, 2.5, 2.5]
))
fig.add_trace(go.Scattercarpet(
name = "a = 0.15",
a = [0.15, 0.15, 0.15, 0.15],
b = [0.5, 1.5, 2.5, 3.5],
line = dict(
smoothing = 1,
shape = "spline"
)
))
fig.add_trace(go.Scattercarpet(
name = "a = 0.2",
a = [0.2, 0.2, 0.2, 0.2],
b = [0.5, 1.5, 2.5, 3.5],
line = dict(
smoothing = 1,
shape = "spline"
),
marker = dict(
size = [10, 20, 30, 40],
color = ["#000", "#f00", "#ff0", "#fff"]
)
))
fig.add_trace(go.Scattercarpet(
name = "a = 0.25",
a = [0.25, 0.25, 0.25, 0.25],
b = [0.5, 1.5, 2.5, 3.5],
line = dict(
smoothing = 1,
shape = "spline"
)
))
fig.update_layout(
title = "scattercarpet extrapolation, clipping, and smoothing",
hovermode = "closest"
)
fig.show()
Reference¶
See https://plotly.com/python/reference/scattercarpet/ for more information and chart attribute options!
What About Dash?¶
Dash is an open-source framework for building analytical applications, with no Javascript required, and it is tightly integrated with the Plotly graphing library.
Learn about how to install Dash at https://dash.plot.ly/installation.
Everywhere in this page that you see fig.show()
, you can display the same figure in a Dash application by passing it to the figure
argument of the Graph
component from the built-in dash_core_components
package like this:
import plotly.graph_objects as go # or plotly.express as px
fig = go.Figure() # or any Plotly Express function e.g. px.bar(...)
# fig.add_trace( ... )
# fig.update_layout( ... )
from dash import Dash, dcc, html
app = Dash()
app.layout = html.Div([
dcc.Graph(figure=fig)
])
app.run(debug=True, use_reloader=False) # Turn off reloader if inside Jupyter
