Plotly Chart Quality Guide
This page contains tips on adding a Plotly Chart to a Text Panel content successfully.
Axis Scaling for Narrow Data Bands
A common defect is using a zero baseline or an overly wide axis when the data occupies a narrow band. This is especially relevant when comparing Grid Overlay values across Neighborhoods or Areas, where values often fall within a tight range.
When to avoid a zero baseline
Avoid forcing the axis to zero when:
- the data range is narrow,
- zero is not a meaningful reference,
- the purpose is to compare small differences between categories.
Example situation:
- all values are within a few units of each other,
- a zero baseline makes all bars look almost identical.
In that case, use a data-driven range.
Data-driven range
Compute the range from the data. In JavaScript:
const minValue = Math.min.apply(null, values);
const maxValue = Math.max.apply(null, values);
const span = maxValue - minValue;
const padding = Math.max(span * 0.15, 0.5);
const yMin = minValue - padding;
const yMax = maxValue + padding;Then apply:
yaxis: {
range: [yMin, yMax]
}Choose dtick sensibly
Choose a `dtick` that produces a readable number of ticks:
yaxis: {
range: [yMin, yMax],
dtick: 1
}Too many ticks clutter the chart. Too few ticks hide structure.
Disclose truncation
If the axis does not start at zero, add a footnote in the panel HTML:
<p class="footnote">
The y-axis is zoomed to emphasize differences between categories.
</p>This prevents readers from misinterpreting bar lengths.
Avoid excessively wide ranges
An axis range much wider than the data spread wastes space and reduces comparability.
If the data spread is small, do not use a range that is many times larger than the spread unless there is a strong analytical reason.
Value labels
When precise comparison matters, display values on or above the bars:
text: values.map(v => v.toFixed(1) + "°C"),
textposition: "outside"Ensure the top margin is large enough to show outside labels. See Text Panel Content Guidelines#Encoding_Special_Characters_in_JavaScript_Strings for details on encoding special characters in JavaScript strings.
Preventing Clipped Category Labels
Clipped x-axis labels are a common rendering defect, especially when category names are long.
Increase bottom margin
Rotated labels need vertical space:
margin: {
b: 140
}If labels are still clipped, increase the bottom margin further.
Use automargin
Enable automatic margin adjustment where supported:
xaxis: {
automargin: true
}This is helpful but not a substitute for verifying the rendered image.
Control tick angle
Use a moderate angle:
xaxis: {
tickangle: -45
}Very steep angles can require excessive bottom margin.
Reduce font size cautiously
Reducing font size can help, but only if the labels remain readable:
xaxis: {
tickfont: { size: 11 }
}Abbreviate long names
If full names are impractical, use controlled abbreviations and explain them in a footnote or tooltip.
Use horizontal bars
Horizontal bar charts are often better for long category names:
{
type: "bar",
x: values,
y: names,
orientation: "h"
}This moves category labels to the y-axis, where they often have more room.
Test with the longest label
During development, test the layout using the longest expected category name, not only the current sample data.
Coloring Bar Charts by Value
A colorscale only affects a Plotly bar trace when the trace has a color array.
Required pattern
const trace = {
type: "bar",
x: names,
y: values,
marker: {
color: values,
colorscale: "Reds",
cmin: colorMin,
cmax: colorMax,
showscale: true,
colorbar: {
title: { text: "PET (°C)" },
thickness: 14,
len: 0.8
}
}
};The critical property is:
color: valuesWithout it, `colorscale`, `cmin`, and `cmax` may have no visible effect, and the bars may render in the default color.
Continuous data needs continuous encoding
For continuous quantitative data, use a continuous colorscale.
Do not use a fixed positional palette where the first bar is always one color, the second bar another color, and so on, unless the position itself is meaningful.
Positional coloring can be misleading when bars are sorted by value.
Add a colorbar
When using a continuous colorscale, show a colorbar:
showscale: true,
colorbar: {
title: { text: "Metric (unit)" },
thickness: 14,
len: 0.8
}Reserve right margin for the colorbar:
margin: {
r: 70
}Categorical coloring
If using discrete categories, use a legend:
showlegend: trueMake sure the legend explains what each color means.
Verify the rendered gradient
Source code can look correct while the rendered chart still uses default colors. Always verify the final image. See Text Panel Content Guidelines#Quality_assurance for the full rendered-image checklist.
Choosing Color Domain Bounds
Even when `marker.color` is present, the color domain can still be misleading.
The minimum-value problem
Sequential scales such as `Reds` often start with a very light or near-white color. If `cmin` is set exactly to the data minimum, the minimum value maps to the lightest end of the scale and may appear gray or white.
This can make the lowest-value category look like missing data.
Pad the lower bound
Compute a padded lower bound:
const minValue = Math.min.apply(null, values);
const maxValue = Math.max.apply(null, values);
const span = maxValue - minValue;
const colorPadding = Math.max(span * 0.15, 0.5);
const colorMin = minValue - colorPadding;
const colorMax = maxValue + colorPadding;Then use:
marker: {
color: values,
colorscale: "Reds",
cmin: colorMin,
cmax: colorMax
}This keeps the minimum value visibly colored.
Dynamic vs fixed bounds
Prefer dynamic bounds with padding:
cmin: minValue - padding,
cmax: maxValue + paddingUse fixed bounds only when:
- the data domain is stable,
- the fixed bounds are documented,
- the fixed bounds are known to keep all values visible.
Hardcoded bounds can become stale when scenarios, iterations, or timeframes change.
Verify extremes
Always check that:
- the minimum value is not near-white,
- the maximum value is not saturated into an unreadable block,
- intermediate values are distinguishable,
- the colorbar matches the actual bar colors.