密谋-设置线条颜色

时间:2019-10-01 16:17:41

标签: python-3.x plotly plotly-python

如何设置plotly中线条的颜色?

import plotly.graph_objects as go
from plotly.subplots import make_subplots


fig = make_subplots(rows=2, cols=1, subplot_titles=('Plot 1', 'Plot 2'))

# plot the first line of the first plot
fig.append_trace(go.Scatter(x=self.x_axis_pd, y=self.y_1, mode='lines+markers', name='line#1'), row=1, col=1)  # this line should be #ffe476

我尝试了fillcolor,但我怀疑这行不通,因为它很简单。

4 个答案:

答案 0 :(得分:2)

您可以在line=dict(color="#ffe476")通话中添加go.Scatter(...)。这里的文档:https://plot.ly/python/reference/#scatter-line-color

答案 1 :(得分:2)

@nicolaskruchten当然是正确的,但我想提出另外两个选择:

line_color="#0000ff"

 fig['data'][0]['line']['color']="#00ff00"

我特别感谢后一种选择的灵活性,因为它很容易让您使用例如fig.append_trace(go.Scatter())或{{ 1}}。下面是使用这三个选项的示例。

代码1:

fig = go.Figure(data=go.Scatter))

情节1:

enter image description here

现在,如果您将下面的代码段插入新的单元格并运行它,则可以直接更改颜色。

代码2:

import plotly.graph_objects as go
import numpy as np

t = np.linspace(0, 10, 100)
y = np.cos(t)
y2= np.sin(t)
fig = go.Figure(data=go.Scatter(x=t, y=y,mode='lines+markers', line_color='#ffe476'))
fig.add_trace(go.Scatter(x=t, y=y2,mode='lines+markers', line=dict(color="#0000ff")))
fig.show()

图2:

enter image description here

答案 2 :(得分:0)

fig.add_trace(
                go.Scatter(
                    x=list(dict_val['yolo_timecost'].keys()),
                    y=signal.savgol_filter(list(dict_val['yolo_timecost'].values()),2653,3),
                    mode='lines',
                    name='YOLOv3实时耗时',
                    line=dict(
                        color='rgb(204, 204, 204)',
                        width=5
                    ),
                    ),
                )

答案 3 :(得分:0)

fig.data[0].line.color = 'rgb(204, 20, 204)'