问题
I am trying to display 1,1.5,4,7,9 in X axis and 2.5,1,5,3 in Y axis. When I tried to do this, my output is like 1, 1.5, 2, 2.5,...... which is basically breakdown of values which I have given. I want only values which I have given in XY axis and I don't want auto range(Scroll value).
回答1:
Assuming you are using JavaScript since you tagged angular.
You are going to have to set three attributes to make this work: tickvals, ticktext, and tickmode. In the documentation you they tell you:
tickmode ( enumerated : "auto" | "linear" | "array" )
Sets the tick mode for this axis. If "auto", the number of ticks is set vianticks. If "linear", the placement of the ticks is determined by a starting positiontick0and a tick stepdtick("linear" is the default value iftick0anddtickare provided). If "array", the placement of the ticks is set viatickvalsand the tick text isticktext. ("array" is the default value iftickvalsis provided).tickvals (data array) Sets the values at which ticks on this axis appear. Only has an effect if
tickmodeis set to "array". Used withticktext.ticktext (data array) Sets the text displayed at the ticks position via
tickvals. Only has an effect iftickmodeis set to "array". Used withtickvals.
So tickmode says you want to use your own labels, tickvals says where to put those labels, and ticktext are your labels. Setting tickvals and ticktext should make Plotly infer tickmode so you should be able to omit this if you want. Using something like the following should help you achieve your goal:
var layout = {
xaxis: {
tickmode: "array",
tickvals: [1,1.5,4,7,9],
ticktext: [1,1.5,4,7,9]
},
yaxis: {
tickvals: [1,1.5,4,7,9],
ticktext: [1,1.5,4,7,9]
}
}
This example Should help.
来源:https://stackoverflow.com/questions/51324556/display-given-value-in-xy-axis-plotly