![](/img/trans.png)
[英]Python: How do I change the colors of lines on a multi-line chart in plotly?
[英]Plotly: How to plot a multi-line chart?
我有一个二维列表,我想创建一个Plotly 多折线图来表示这些数据。
到目前为止,我有这个代码:
print(len(conv_loss),len(conv_loss[0]))
print(np.array(conv_loss).shape)
conv_loss_df = pd.DataFrame(data=conv_loss, index=namelist, columns=rs)
print(conv_loss_df)
输出:
4 10
(4, 10)
0.0 0.1 0.2 ... 0.7 0.8 0.9
mnist 0.020498 0.123125 0.222588 ... 1.122625 1.387823 1.701249
fashion_mnist 0.232772 0.316569 0.433325 ... 1.281240 1.545556 1.830893
cifar10 0.957889 0.851946 0.921106 ... 1.645510 1.815194 2.104631
cifar100 3.516734 3.052485 3.021778 ... 3.688753 3.937770 4.599526
我希望图表的 x 轴是rs
, colors 是namelist
,而 y 轴是各自的数据本身。
我已经玩过他们为 plotly 折线图提供的示例,但我似乎无法让它工作。
我必须让它不出错的方法是:
fig = px.line(conv_loss_df,x=rs)
fig.show()
可以通过将给定数据转置的数据框作为目标来绘制所需的图形。 这是使用示例数据创建的。
import numpy as np
import pandas as pd
import plotly.express as px # plotly ver 4.14.1
import random
rs = np.arange(0.1, 1.0, 0.1)
namelist = ['mnist', 'Fasion_mnist','cifar10','cifar100']
mnist = np.random.rand(9)
fasion_mnist = np.random.rand(9)
cifar10 = np.random.rand(9)
cifar100 = np.random.rand(9)
conv_loss_df = pd.DataFrame([mnist,fasion_mnist,cifar10,cifar100], index=namelist, columns=rs)
conv_loss_df.T
fig = px.line(conv_loss_df.T)
fig.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.