plotly/rotated-tick-labels
| Rule | rotated-tick-labels |
|---|---|
| Pack | plotly |
| Severity | info, and warning with style = "strict". A rule of the house style |
| Fix | none, edit by hand |
| Library versions | every version |
Tick labels turned away from the horizontal are harder to read. For long category names, put the categories on y with a horizontal bar chart.
fig = px.bar(df, x="answer", y="share")fig.update_xaxes(tickangle=-90)fig = px.bar(df, x="share", y="answer", orientation="h")What the rule reports
Section titled “What the rule reports”The rule reports a tickangle written as a number other than 0, 180 and 360, on an x or y axis of a plotly figure. It reads the keyword in update_xaxes, update_yaxes, go.layout.XAxis and go.layout.YAxis, the underscore form such as xaxis_tickangle in update_layout and go.Layout, and xaxis=dict(tickangle=...) or xaxis={"tickangle": ...} in update_layout, go.Layout and go.Figure.
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
The book lists as friendly "words run from left to right, the usual direction for reading
occidental languages", and as unfriendly "words run vertically, particularly along the Y-axis;
words run in several different directions" (page 183). plotly keeps a tickangle as written.
update_xaxes(tickangle=-90) resolved to -90, and both category labels of a bar chart were drawn
rotated. With the categories on y, as in px.bar(orientation="h"), every tick label was
drawn level.
The rule has no fix, because tickangle=0 can make long labels run into each other, and the
level layout swaps x and y. An angle given by a name is left alone, and so is the tickangle
of a colorbar.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
tickangle=$A turns the tick labels away from the horizontal. Tufte lists words that run from left to right as friendly and words that run vertically as unfriendly. For long category names, put the categories on y, as px.bar(orientation="h") does, and the labels stay level.Browse the other rules of the plotly pack.