绘制数据FI时图例工作不正常

2024-09-28 22:20:05 发布

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

我有3个不同的数据集,它们都有相同的变量。第一个数据集是一个控件,第二个数据集除压力外略有扰动,最后一个数据集除压力外也略有扰动。我在《使用熊猫》中读到了这些,并创作了一个情节。但是,图例无法正常工作。当我希望它们都是各自颜色的温度时,它将每条线显示为压力。我也希望能够编辑他们说'温度(控制),等等。这是我的代码和情节:

import matplotlib.pyplot as plt
import pandas as pd
control=pd.read_csv("Control.csv")
control.columns=['Pressure', 'Temperature', 'specific humidity', 'buoyancy of air lifted from the lowest model level', 'relative humidity', 'convective heating rate', 'radiative heating rate', 'turbulent heating rate', 'a', 'b', 'c', 'd', 'e', 'f', 'g','cloud fraction','h', 'i', 'j', 'k' ]
albedo_only=pd.read_csv("Albedo 0.2.csv")
albedo_only.columns=['Pressure', 'Temperature', 'specific humidity', 'buoyancy of air lifted from the lowest model level', 'relative humidity', 'convective heating rate', 'radiative heating rate', 'turbulent heating rate', 'a', 'b', 'c', 'd', 'e', 'f', 'g','cloud fraction','h', 'i', 'j', 'k' ]
albedo_ocean=pd.read_csv("Albedo 0.2 Ocean 0.8.csv")
albedo_ocean.columns=['Pressure', 'Temperature', 'specific humidity', 'buoyancy of air lifted from the lowest model level', 'relative humidity', 'convective heating rate', 'radiative heating rate', 'turbulent heating rate', 'a', 'b', 'c', 'd', 'e', 'f', 'g','cloud fraction','h', 'i', 'j', 'k' ]


ax=control.plot(x='Temperature', y='Pressure', kind='line', legend=True, 
title='Atmospheric Temperature')
albedo_only.plot(x='Temperature', y='Pressure', ax=ax)
albedo_ocean.plot(x='Temperature', y='Pressure', ax=ax)
plt.gca().invert_yaxis()
plt.xlim(-80, 30)
plt.xlabel('Temperature (C)')
plt.ylabel('Pressure (hPa)')
ax.legend()
plt.show()

enter image description here


Tags: columnscsv数据readratepltaxcontrol