Scatter plots

A scatter plot shows the relationship between up to three variables by plotting each point on a coordinate plane, where the position of the point corresponds to the values of the variables being compared.

By examining the pattern and distribution of the points, you can identify relationships, correlations, and trends in the data, such as whether there’s a strong connection or no correlation between the variables.

Hide code cell source
import plotly.io as pio

pio.renderers.default = "sphinx_gallery"
import plotly.express as px
import statsplotly

A simple 2-dimensional plot, with a diamond marker:

df = px.data.tips()

fig = statsplotly.plot(
    data=df,
    marker="diamond",
    x="total_bill",
    y="tip",
    slicer="sex",
)
fig.show()

3D plots

Supplying a z dimension generates a 3-dimensional scatter:

df = px.data.tips()

fig = statsplotly.plot(
    data=df,
    marker="diamond",
    x="total_bill",
    y="tip",
    z="day",
    slicer="sex",
)
fig.layout.height = 600
fig.show()

Controlling data points colormapping

Color can be specified independently of the slicer:

df = px.data.tips()

fig = statsplotly.plot(data=df, x="total_bill", y="tip", z="day", slicer="sex", color="tip")
fig.layout.height = 600
fig.show()

Discrete color mapping

Supplying a string color dimension creates a discrete colormap:

df = px.data.tips()

fig = statsplotly.plot(data=df, x="total_bill", y="tip", z="day", slicer="sex", color="day")
fig.layout.height = 600
fig.show()

Full details of the API : plot().