plotly/area-axis-without-zero
| Rule | area-axis-without-zero |
|---|---|
| Pack | plotly |
| Severity | warning |
| Fix | none, edit by hand |
| Library versions | every version |
An area chart whose value axis starts above zero draws fills whose height no longer follows their value. Let the axis start at 0, or draw lines instead of filled areas.
fig = px.area(df, x="month", y="sales", range_y=[90, 101])fig = px.area(df, x="month", y="sales")line = px.line(df, x="month", y="sales", range_y=[90, 101])What the rule reports
Section titled “What the rule reports”The rule reports an area chart whose value axis is given a range that starts above zero: range_y on px.area, and on a figure of filled areas update_yaxes(range=...), update_layout(yaxis_range=...) and update_layout(yaxis=dict(range=...)).
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
An area chart shows its value by the height of the fill below the line. plotly starts the axis
of px.area and of go.Scatter(fill="tozeroy") at zero by itself. It keeps an explicit range
as written and cuts the fill at the lower edge of the plot, a Lie Factor of 19 as for a bar.
| Values 95 and 100 | Range | Fill heights in pixels |
|---|---|---|
px.area |
0 to 105.26, chosen by plotly | 324.9 and 342.0, the ratio of the values |
[90, 101] set in px.area, in update_yaxes or in update_layout |
90 to 101 | 163.6 and 327.3 |
px.line |
94.72 to 100.28, chosen by plotly | no fill |
A line chart needs no zero, so the replacement draws the narrow range with px.line.
The rule reads a range as bar-axis-without-zero does. Both ends must
be written numbers above zero, and the lower end must have as many digits before the point as
the upper end, or one fewer. A call with orientation or log_y is left alone, and a range set on the
figure afterwards is left alone in a file that names a log axis. A figure of filled areas is
px.area without orientation and log_y, or a go.Figure(...) whose own arguments hold a
go.Scatter with fill="tozeroy".
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
range_y=$R starts the axis of the area chart above zero, so the height of the fill no longer follows its value. With [90, 101], fills for 95 and 100 were drawn 163.6 and 327.3 pixels tall, a Lie Factor of 19 by Tufte's measure. Let the axis start at 0, or draw the values as a line with px.line, which needs no zero.Browse the other rules of the plotly pack.