As I mentioned in my comment on the OP:
I'm fairly confident plotly does not give this ability directly. The only way I can think of to do it would be super convoluted: put two axes on your plot. One can be totally normal except the tick label for the red tick should be set to an empty string. The other axes would just have the one red tick label and all other labels set to empty string. And then position them so that they're on top of each other.
This definitely sucks, but it does work:
import plotly.graph_objs as go
data = [go.Scatter(
x=[1, 2, 3, 4],
y=[4, 5, 6, 7],
name="data"
), go.Scatter(xaxis='x2')]
layout = go.Layout(
xaxis=dict(
range=[0, 5],
title="xaxis title",
tickfont=dict(color="#1f77b4"),
tickmode='array',
tickvals=[1, 2, 3],
ticktext=['a', 'b', 'c'],
),
xaxis2=dict(
range=[0, 5],
tickfont=dict(color="#ff7f0e"),
tickmode='array',
tickvals=[4],
ticktext=['d'],
overlaying="x",
side="bottom",
)
)
fig = go.Figure(data=data, layout=layout)
fig.show()
A couple of notes:
- I added an empty trace, otherwise I couldn't get the second axis to show up. There might be a way to show the second axis without doing that, but I couldn't figure out how.
- The range has to be set the same on both, otherwise the second axis is not scaled with the first, since they can be scaled/translated arbitrarily from each other.
- You have to manually specify the tick locations and values. On the plus side, this is actually somewhat convenient for this particular method.
- The
side='bottom'
doesn't seem to be necessary, at least for this plot, but it may for others and it's explicit anyways so...I kept it in here.
On one hand, the nice thing about this method is that it is somewhat independent of what types of plots you're using. On the other hand, it may be better to convey the difference of information not by the axes labels, but by the style of the information. For e.g., a different colored bar or similar may be more indicative of the difference.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…