如何在以图形方式表示的线图中设置单个线的样式(宽度,颜色,虚线)?

时间:2020-08-27 21:41:59

标签: plotly-python

我正在使用plotly.express.line生成具有三条重叠线的绘图,如下所示:

import plotly.express as px
data_1 = [0,1,4,9,16]
data_2 = [3,4,5,6,7]
data_3 = [16,13,10,7,4]
x_vals = [0,1,2,3,4]
fig = px.line(
    y=[data_1, data_2, data_3],
    labels={"x": "time (steps)", "y": "meaningless quantity"},
    # line_dash=['-', '--', '.'],
    template="plotly_dark",
)
fig.data[0].name, fig.data[1].name, fig.data[2].name = "Thing 1", "Thing 2", "Thing 3"
fig.show()

我想以不同的方式设置每条线的样式-例如,使一条迹线为虚线,而另一条为虚线,或者可能改变一条线的宽度。我在plotly.express.line的文档中发现它有一个可选的参数line_dash,但它没有按我的预期工作:当我在示例中取消注释行时,出现错误:

ValueError: All arguments should have the same length. The length of argument `line_dash` is 3, whereas the length of  previously-processed arguments ['wide_variable_0', 'wide_variable_1', 'wide_variable_2'] is 5

显然,line_dash的参数应该与正在绘制的每个数据列表具有相同的长度。但这对我完全没有意义,因为虚线应该应用于整行,而不是单个数据点。

(我已经找到了一些示例性地对线条进行样式设置的示例,但它们要么全部使用数据帧而不是类似数组的数据,并且/或者使用plotly.graph_objects而不是plotly.express。)

我的问题:

  1. 是否可以在不使用数据框的情况下以情节表达方式对单个线条进行样式设置?
  2. line_dash的{​​{1}}和line_width(以及类似参数)的目的是什么,看来似乎是行事的?

谢谢…

0 个答案:

没有答案