3D plots¶
In [1]:
Copied!
import plotly.express as px
import plotly.graph_objects as go
import arcadia_pycolor as apc
apc.plotly.setup()
import plotly.express as px
import plotly.graph_objects as go
import arcadia_pycolor as apc
apc.plotly.setup()
1. 3D scatter plot with Plotly Express¶
In [2]:
Copied!
df = px.data.iris()
fig = px.scatter_3d(
df,
x="sepal_length",
y="sepal_width",
z="petal_width",
color="species",
size="sepal_length",
color_discrete_map={
"setosa": apc.aegean,
"versicolor": apc.amber,
"virginica": apc.seaweed,
},
)
apc.plotly.style_plot(fig, monospaced_axes="all")
fig.show()
df = px.data.iris()
fig = px.scatter_3d(
df,
x="sepal_length",
y="sepal_width",
z="petal_width",
color="species",
size="sepal_length",
color_discrete_map={
"setosa": apc.aegean,
"versicolor": apc.amber,
"virginica": apc.seaweed,
},
)
apc.plotly.style_plot(fig, monospaced_axes="all")
fig.show()
2. 3D scatter plot with Plotly Graph Objects¶
In [3]:
Copied!
fig = go.Figure()
fig.add_trace(
go.Scatter3d(
x=df["sepal_length"],
y=df["sepal_width"],
z=df["petal_width"],
mode="markers",
marker=dict(
size=5,
color=df["species"].map(
{
"setosa": apc.aegean,
"versicolor": apc.amber,
"virginica": apc.seaweed,
}
),
opacity=0.8,
),
text=df["species"],
hoverinfo="text",
)
)
fig.update_layout(
scene=dict(
xaxis_title="sepal_length",
yaxis_title="sepal_width",
zaxis_title="petal_width",
),
showlegend=False,
)
apc.plotly.style_plot(fig, monospaced_axes="all")
fig.show()
fig = go.Figure()
fig.add_trace(
go.Scatter3d(
x=df["sepal_length"],
y=df["sepal_width"],
z=df["petal_width"],
mode="markers",
marker=dict(
size=5,
color=df["species"].map(
{
"setosa": apc.aegean,
"versicolor": apc.amber,
"virginica": apc.seaweed,
}
),
opacity=0.8,
),
text=df["species"],
hoverinfo="text",
)
)
fig.update_layout(
scene=dict(
xaxis_title="sepal_length",
yaxis_title="sepal_width",
zaxis_title="petal_width",
),
showlegend=False,
)
apc.plotly.style_plot(fig, monospaced_axes="all")
fig.show()