Display given value in XY axis - Plotly

浪子不回头ぞ 提交于 2021-02-11 13:41:33

问题


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 via nticks. If "linear", the placement of the ticks is determined by a starting position tick0 and a tick step dtick ("linear" is the default value if tick0 and dtick are provided). If "array", the placement of the ticks is set via tickvals and the tick text is ticktext. ("array" is the default value if tickvals is provided).

tickvals (data array) Sets the values at which ticks on this axis appear. Only has an effect if tickmode is set to "array". Used with ticktext.

ticktext (data array) Sets the text displayed at the ticks position via tickvals. Only has an effect if tickmode is set to "array". Used with tickvals.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!