我有一个如下所示的数据集。我需要以这样的方式从中创建一个折线图,即所有以黄色显示的列都应位于 X 轴中,而以绿色显示的列需要位于 Y 轴中轴。我可以知道如何处理这个吗。
我期待像下面这样的情节
运行代码后得到的图表
答案 0 :(得分:1)
您可以尝试以下操作吗?正如我在评论中所述,您需要从希望用作 X 轴的 3 列中创建一个索引值:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from pylab import rcParams
rcParams['figure.figsize'] = 12, 5
df = pd.read_excel(file_location).ffill()
sns.lineplot(x=df['Device_ID'].astype(str)+df['Temp(deg)'].astype(str)+'-'+df['Supply[v]'].astype(str),
y=df[2.4],color='r')
sns.lineplot(x=df['Device_ID'].astype(str)+df['Temp(deg)'].astype(str)+'-'+df['Supply[v]'].astype(str),
y=df[3.07],color='b')
plt.legend(['2.4','3.07'])
plt.ylabel('Frequency[MHz]')
plt.tick_params(axis='x',labelsize=8)
输出:
答案 1 :(得分:0)
import pandas as pd
from matplotlib import pyplot as plt
plt.plot(df[x], df[y_1], label="y_1")
plt.plot(df[x], df[y_2], label="y_2")
plt.legend()
plt.show()