简体   繁体   English

Pandas多数据集图错误

[英]Pandas multiple dataset plot error

I have multiple datasets that I need to be plotted on the same axes. 我有多个数据集,我需要在同一轴上绘制。 Just an example of the datasets are: Dataset 01 as two separate lists: 只是数据集的一个示例是:数据集01作为两个单独的列表:

Waves          Values
340            520
341            532
342            536
.              .
.              .
2500           720

Dataset 02 as a dataframe df: 数据集02作为数据帧df:

Wavelength      Data
320             560
350             572
.               .
.               .
2650            780

My attempt at the plot is as follows: 我对情节的尝试如下:

fig,ax=plt.subplots(figsize=(15, 10))
ax = plt.plot(x = Waves , y = Values)   # list names
df.plot(ax=ax, x='Wavelength', y='Data')
plt.show()

I get the following error: 我收到以下错误:

AttributeError: 'list' object has no attribute 'get_figure'

样本输出图

You redefine the axes ax , created in the first line, to be a list of lines via ax=plt.plot(..) . 您可以通过ax=plt.plot(..)重新定义在第一行中创建的ax轴作为行列表。 Remove this redefinition. 删除此重新定义。

fig,ax=plt.subplots(figsize=(15, 10))
ax.plot(Waves, Values)
df.plot(ax=ax, x='Wavelength', y='Data')
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM