Three-way composition analysis
Compare how three quantities are divided across observations, such as candidate support or mixture composition.
Plotly · Function
Creates an interactive ternary scatter plot with Plotly Express, representing each data-frame row as a point. The a, b, and c arguments define the three ternary components, while optional encodings can control color, size, and hover content.
px.scatter_ternary builds a complete interactive ternary scatter figure from tabular data. The a, b, and c arguments provide the three component values; optional encodings such as color, marker size, and hover labels add dimensions to each row.
plotly.express.scatter_ternary([data_frame, a, b, c, ...])import plotly.express as px
df = px.data.election()
fig = px.scatter_ternary(
df, a="Joly", b="Coderre", c="Bergeron",
color="winner", size="total", hover_name="district",
size_max=15,
)
fig.show()Creates an interactive ternary scatter chart from Plotly's built-in election dataset, encoding three component columns as coordinates and additional columns as color, size, and hover text.
Compare how three quantities are divided across observations, such as candidate support or mixture composition.
Add categorical color and quantitative size to reveal extra dimensions in the same ternary view.
px.scatter_ternary create, and how are observations represented?It is a Plotly Express function for creating ternary scatter plots. Each row in the supplied data frame is represented by a point, positioned using the three component variables.
Follow-up: How would you add a fourth variable? Encode it through an available visual channel such as color, marker size, symbol, or hover information.
Pass the data frame plus the a, b, and c column names. Optional arguments such as color, size, and hover_name control additional point encodings and interaction details.
Follow-up: How can the resulting figure be displayed? Call fig.show() after assigning the returned figure.
The function is part of Plotly Express, Plotly's high-level interface for rapid figure generation. It returns a Plotly figure that can be displayed and further customized.
Follow-up: When would a lower-level API be preferable? Use a graph-object ternary trace when direct control over trace and layout attributes is required.
plotly.expressline_ternaryscatterplotly.graph_objects.Scatterternary