简体   繁体   English

如何在Plotly Express平行坐标绘图中设置刻度格式?

[英]How do I format ticks in a Plotly Express Parallel Coordinates plot?

I'm creating a parallel coordinates plot using Plotly express, but I can't seem to format the ticks on the y-axis how I'd like. 我正在使用Plotly express创建一个平行坐标图,但是我似乎无法按照自己的意愿格式化y轴上的刻度。 You can see in the plot below that the ticks have numbers like 900m; 您可以在下面的图中看到,刻度线的数字为900m。 I just want them formatted as 0.9. 我只希望它们格式化为0.9。

情节

This seems to be coming from the exponentformat argument of the y-axis, based on the help string: 这似乎来自y轴的exponentformat参数,基于帮助字符串:

exponentformat exponentformat

Determines a formatting rule for the tick exponents. 确定刻度指数的格式化规则。 For example, consider the number 1,000,000,000. 例如,考虑数字1,000,000,000。 If "none", it appears as 1,000,000,000. 如果为“ none”,则显示为1,000,000,000。 If "e", 1e+9. 如果为“ e”,则为1e + 9。 If "E", 1E+9. 如果为“ E”,则为1E + 9。 If "power", 1x10^9 (with 9 in a super script). 如果为“ power”,则为1x10 ^ 9(超级脚本中为9)。 If "SI", 1G. 如果为“ SI”,则为1G。 If "B", 1B. 如果为“ B”,则为1B。

So I've tried to change this argument using the update_yaxes method. 因此,我尝试使用update_yaxes方法更改此参数。 However, the plot looks the same. 但是,该图看起来相同。 How do I change the tick format to normal decimal numbers like 0.9 instead of 900m? 如何将刻度格式更改为普通的十进制数字(如0.9)而不是900m?

Code to reproduce the plot (using Plotly version 4.0.0): 重现绘图的代码(使用Plotly 4.0.0版):

import pandas as pd
import numpy as np
import plotly.express as px

data = pd.DataFrame({c: np.random.rand(30) for c in "abcd"})
fig = px.parallel_coordinates(
    data,
    color="d",
    color_continuous_scale=px.colors.sequential.Viridis,
)
fig.update_yaxes(exponentformat="none")
fig.show()

Plotly中的平行坐标图的尺寸不是使用layout.yaxis属性配置的,而是在data[].dimensions[].tickformat ,该文档在此处进行了记录: https : data[].dimensions[].tickformat parcoords维度项维-tickformat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM