✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

How to gather auto-generated axis values and use them

I have used plotly to create a graph. X axis are timestamps and Y value are “CPU” values. These are actually Erlang reductions so the numbers can be quite large. In my current case, the auto-generated Y axis starts around -2,000,000 and goes up to ~70,000,000.

I wanted to add a representation of an event happening along the range of the graph. I am running tests and what I am working on will impact what happens to Erlang, so that timing is pertinent. I wanted to put a “tick” as a vertical line starting below the 0 x axis and ranging up to 0. This way, these “ticks” won’t overlap any “real” data as it is all positive. If I manually add a trace, or shape, or whatever ranging from -1,000,000 to 0, the size works nicely and it looks like what I want. The user can hover over and see the tooltip which I explain what happened at this time. All works great.

However, then I run a new data set where the Y values range from -10 to 70 and my hard coded value of -1,000,000 skews the graph.

Is there a way of polling the graph for what the max/min Y values are so that I can create this “tick” the appropriate size for any graph?

Is there another feature in plotly that would allow me to accomplish the same thing?

Thank you

It turns out you can do this with a shape and have the ref set to ‘paper’. The problem with this solution is there is no tooltip for shapes. One recommendation here is to have associated scatter points with tooltips. If I were to do this, I would want the point on the “edge” of the graph. If I could accomplish this, I wouldn’t need the shape in the first place, I could just create the Scatter line to the edge of the graph area.

I ended up using a “marker” on the x axis. Not exactly what I wanted, but seems to do the job.