Python:如何在绘图中更改多折线图上线条的颜色? [复制]
Posted
技术标签:
【中文标题】Python:如何在绘图中更改多折线图上线条的颜色? [复制]【英文标题】:Python: How do I change the colors of lines on a multi-line chart in plotly? [duplicate] 【发布时间】:2022-01-15 13:24:33 【问题描述】:如何更改下面图表中线条的颜色?谢谢
import plotly.express as px
# forecast_eval is a dataframe with an actual number, a forecast
# number, and upper and lower forecast bounds
# Draw a line chart using 4 columns forecast_eval.columns[2:6]
eval_line = px.line(forecast_eval, x='ds', y=forecast_eval.columns[2:6],
title='Forecast')
eval_line
Line chart
【问题讨论】:
【参考方案1】: 您尚未提供示例数据,已模拟示例代码所暗示的相同结构的数据框 使用color_discrete_sequence的简单案例import plotly.express as px
import numpy as np
import pandas as pd
# forecast_eval is a dataframe with an actual number, a forecast
# number, and upper and lower forecast bounds
forecast_eval = pd.concat(
[
pd.DataFrame("ds": np.linspace(0, 100, 1000)),
pd.DataFrame(
np.random.uniform(np.linspace(0, 10**4, 5), np.linspace(1, 2*10**4, 5), [1000, 5])
),
],
axis=1,
)
# Draw a line chart using 4 columns forecast_eval.columns[2:6]
eval_line = px.line(
forecast_eval,
x="ds",
y=forecast_eval.columns[2:6],
title="Forecast",
color_discrete_sequence=["yellow", "blue", "pink", "skyblue"],
)
eval_line
【讨论】:
以上是关于Python:如何在绘图中更改多折线图上线条的颜色? [复制]的主要内容,如果未能解决你的问题,请参考以下文章
Python:如果超出特定范围,是不是可以更改绘图中的线条颜色?
python使用matplotlib可视化线图(line plot)在可视化图像中的指定位置添加横线自定义线条的颜色自定义线条的形式(add horizontal line)
python使用matplotlib可视化线图(line plot)在可视化图像中的指定位置指定范围添加横线自定义线条的颜色自定义线条的形式(add horizontal line)