为什么不是所有的因子变量都出现在图例中?

2024-09-28 17:29:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我对使用matplotlib绘图非常陌生,我对图例有一些问题,我有以下数据集:

        Wavelength       CD  Time
0          250.0  0.00000     1
1          249.8 -0.04278     1
2          249.6 -0.03834     1
3          249.4 -0.02384     1
4          249.2 -0.04817     1
...          ...      ...   ...
3760       200.8  0.99883    15
3761       200.6  0.50277    15
3762       200.4 -0.19228    15
3763       200.2  0.81317    15
3764       200.0  0.90226    15

[3765 rows x 3 columns]

列类型:

Wavelength    float64
CD            float64
Time            int64
dtype: object

为什么以时间作为分类变量绘制时,图例中未显示所有值

x = df1['Wavelength']
y = df1['CD']
z = df1['Time']

sns.lineplot(x, y, hue = z)
plt.tight_layout()
plt.show()

Lineplot

但我可以使用内置的matplotlib函数和颜色条进行绘图,如下所示:

df1.plot.scatter('Wavelength', 'CD', c='Time', cmap='RdYlBu')

scatter plot

使用matplotlib/seaborn在离散图例和连续图例之间进行选择的最佳方式是什么? 非常感谢


Tags: columns数据绘图类型timematplotlibcdplt