【发布时间】:2020-07-31 19:24:06
【问题描述】:
我正在使用 matplotlib 在数据框中绘制两个数据集。数据集由不同的线型表示。以下是代码。
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
df1 = pd.DataFrame(np.random.randn(10, 16))
df2 = pd.DataFrame(np.random.randn(10, 16))
plt.figure()
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12, 8))
df1.plot(ax=axes[0], style='-', legend=True)
axes[0].set_xlabel('x')
axes[0].set_ylabel('y')
axes[0].set_title('ttl')
df2.plot(ax=axes[0], style='--', legend=True)
axes[0].set_xlabel('x')
axes[0].set_ylabel('y')
axes[0].set_title('ttl')
plt.show()
但是,不同线型的颜色顺序是不同的。例如,line 中的 0
和 dashed line 中的 0 有不同的颜色。我想请教关于如何为两种线条样式获得相同颜色序列的建议。
编辑: 将输入更改为
df1 = pd.DataFrame(np.random.randn(501, 16))
df2 = pd.DataFrame(np.random.randn(5001, 16))
【问题讨论】:
标签: python matplotlib colors comparison legend