Reversed axis with range specified


There is an example here of reversing an axis whilst also specifying a range. However, the range specification doesn’t work for me in a Jupyter notebook. Changing the maximum range to 15 for instance does not affect the plot.


@MrWallace The autorange key can get only one of the following values: True, False or ‘reversed’ ( see ).
An xaxis range greater then the real range of the x-values of your data points is displayed in a Plotly plot only when autorange=False.
But in this case you cannot reverse the xaxis, because autorange=False+‘reversed’ doesn’t work.

If you really want a blank area at the left of your plot,
where to insert an annotation, for example,
then a solution is to add a trace consisting in only one invisible point, of x-coordinate=15:

additional_trace=go.Scatter(x=[15], y=[60], marker=dict(color='white'))
and replace in your code the line
data=[trace, additional_trace]

Hi empet, thanks for your reply. I’m sorry, I perhaps didn’t clarify what I’d like to do.

Let’s say I have some data with a range in x from 0 to 10. I want to display this data on an x-axis which is reversed so 10 is on the left and 0 on the right. However, I’d additionally like to display only a limited range of the whole data, let’s say from 5 to 8 (or 8 to 5, since it’s reversed). I have found that the code in the example I previously linked to does not do what I believe it is meant to be doing. Namely the range=[0, 10] in this code:

xaxis=dict(autorange='reversed', range=[0, 10])

in the example does not seem to have any effect on the plot. If autorange='reversed' is removed, then the range=[...] does have an effect.

In fact I can achieve what I want by simply omitting the autorange and specifying the range as range=[10,0]. So now I’m wondering what is autorange=reversed meant to do that range=[max, min] can’t? Regarding your example, it seems we could achieve some blank space on the left of the reversed plot just by changing the range e.g. range=[max+5, min].


1 Like

The solution is described here: