我有两个CSV文件,我加载到Pandas数据框。然后我绘制一些列到一个图形。不知何故,一个图形可以是任何类型(线,面积,散点,酒吧等),但其他只能是散点。为什么?
下面是我的工作代码,当我将最后一行的kind=“scatter”改为kind=“line”(或其他类型)时,它不会绘图:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('current_speed.csv', sep=';',
parse_dates={ 'datetime':['year','month','day','time_utc'] })
df1 = pd.read_csv('wind_speed.csv', sep=';',
parse_dates={ 'datetimex':['year','month','day','time_utc'] })
fig, ax1 = plt.subplots(1,1)
ax2 = ax1.twinx()
df.plot(x = 'datetime', y = 'curr_speed', color="blue",legend=False, ax= ax1,linewidth=1,alpha=0.4,kind="line")
df1.plot('datetimex', 'wind_speed',ax=ax2, kind="scatter")
以下是数据文件:风速.csv
year;month;day;time_utc;wind_dir;wind_speed;wind_gust
2022;10;27;00:00;280;4.3;8.5
2022;10;27;01:00;268;6.4;8.3
2022;10;27;02:00;272;6.5;8.9
电流_速度.csv
year;month;day;hour;min;sec;time_utc;curr_speed;curr_dir
2022;10;27;13;36;42;13:36;0.174;21.75
2022;10;27;14;36;42;14:36;0.195;38.42
2022;10;27;15;36;42;15:36;0.146;34.15
1条答案
按热度按时间5gfr0r5j1#
这允许您选择所需的任何类型:
或
df1只允许散点图的原因是您正在为此图使用ax2,它与某些类型的图不兼容。次y轴用于与主y轴(ax1)具有不同比例的图,如散点图。