I want to be able to set my own tick markers, and I figured I was able to do that using tickvals. However… I noticed that the last tick will only go as high as the max value on the graph. For example, I have tickvals array = [0,1,2,3,4,5] for the y-axis. The highest value in my y values is ~4.5. On the graph, I am expecting to see 0,1,2,3,4,5 on the y axis ticks but it only goes up to 4 (0,1,2,3,4). I’m thinking this is becuase the max value of my y values is at 4. Is there any way to show all the values despite the max value being lower than the max tickval?
I would also like to implement this in a project I am currently working on.
If you find a solution could you please share it with us as I am unable to find an alternative solution elsewhere on this community forum or on any other Plotly JS resource.
Hi @darrenjwhite i was wondering if the solution @Chiaki provided helped you as this was something i tried in our project however the end result was not what we wanted as we still needed to parse through the data.
What exactly do you guys mean by “parse through the data”? If you’re talking about looking through the data with a machine: there’s no way around it. The program needs to find the highest value in the array and for this it has to “parse” through the whole array to find it. Afterwards you can add +1 to this found value as described above and get what you want.
If you meant looking through the data with a human eye: Holy moly, no you don’t need to do that. Just use Math.max as described above.
I have a bar chart that can display multiple traces of data. I have an user interface built around this bar chart that allows an end user to switch between grouped and stacked modes.
For grouped mode:
The solution you mentioned above will work to an extent. I get the max value from each trace and add 1. Although I want the ticks between the first and last tick to be plotted as whole integers. So this, to the best of my knowledge, requires intensive conditional logic to determine a valid dtick value.
For stacked mode:
In stack mode your solution will simply not work. We need to calculate the max by adding the elements from each respective index from each of our traces. So if we have two traces to be plotted on a bar chart in stacked mode; we would need to add traceOne[0] + traceTwo[0] and traceOne[1] + traceTwo[1] etc, push all these values to a new array then get the max from this new array then perform our conditional logic mentioned above to set the dticks value.
So as you can see, as simple as your solution is, it becomes very intensive in my use case. We have many more use cases where this is applicable.
My question was: Is there any simpler way of telling Plotly you want to see max + n?
I know post render (after you call Plotly.newPlot()) you can access properties for the plot such as max and min values as well as many more. I’m just hesitant to be performing these calculations more than required.
@Chiaki, please either take a step back and try to look at things from our perspective or just leave this discussion as copying and pasting the first link you find from a google search is counter intuitive at this stage. I’m quite capable of doing so myself. Don’t be so patronising. Thanks for your input thus far regardless.
Hi @darrenjwhite your situation sounds very similar to mine I was also hoping for a way to get the values generated from plotly otherwise for me, due to the extreme differences in the data we work with, I have to set some crazy conditional logic. The only other thing I was leaning towards was delving into the plotly library which I do not want to do. If you do come up with a way of achieving this I would be most grateful to you if there was a way you could let me know.
Hi @Chiaki Thanks for your input however I had previously looked into the suggestions you made and as much other stuff I could find relating to the topic before coming here.