在XY轴上显示给定值-绘制 [英] Display given value in XY axis - Plotly

查看:41
本文介绍了在XY轴上显示给定值-绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在X轴上显示 1,1.5,4,7,9 ,在Y轴上显示 2.5,1,5,3 .当我尝试执行此操作时,我的输出类似于 1、1.5、2、2.5,...... ,这基本上是我给出的值的细分.我只想要在XY轴中给定的值,而又不需要自动范围(滚动值).

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).

推荐答案

假设您使用JavaScript是因为您标记了angular.

Assuming you are using JavaScript since you tagged angular.

您将必须设置三个属性才能完成此工作: tickvals ticktext

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 (枚举:自动" |线性" |数组")
设置该轴的刻度模式.如果为自动",则通过 nticks 设置刻度数.如果为线性",则刻度的位置由起始位置 tick0 和刻度步长 dtick 确定(如果 tick0 dtick ).如果为数组",则刻度的位置是通过 tickvals 设置的,刻度文本是 ticktext .(如果提供了 tickvals ,则"array"是默认值).

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 (数据数组)设置此轴上的刻度线出现的值.仅当 tickmode 设置为"array"时才有效.与 ticktext 一起使用.

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 (数据数组)设置通过 tickvals 在刻度位置显示的文本.仅当 tickmode 设置为"array"时才有效.与 tickvals 一起使用.

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.

所以 tickmode 表示您要使用自己的标签, tickvals 表示要放置这些标签的位置,而 ticktext 是您的标签.设置 tickvals ticktext 应该会使Plotly推断 tickmode ,因此,如果需要,您可以忽略此设置.使用类似以下内容的代码可以帮助您实现目标:

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]
    }
}

此示例应该会有所帮助.

这篇关于在XY轴上显示给定值-绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆