【发布时间】:2018-06-21 19:31:40
【问题描述】:
我正在绘制两个条件并且只想要两个图例。但是我的数据中有重复,每个重复我都得到一个单独的图例。为什么?如果之前已经解决了这个问题,我深表歉意,但我在这方面花费了令人尴尬的时间,而且我发现的大部分内容对于我的情况来说似乎过于复杂。任何帮助,将不胜感激。
import matplotlib.pyplot as plt
import pandas as pd
#####read and organize data
alldata = pd.read_csv('Fig_1.csv')
CondtionA = list(zip(alldata.iloc[:,1],alldata.iloc[:,2]))
ConditionB = list(zip(alldata.iloc[:,7],alldata.iloc[:,8]))
### make the figure
fig, ax = plt.subplots()
plt.plot(alldata['Temperature'],ConditionA,linewidth = 1,c='k', linestyle = '--',label = 'ConditionA')
plt.plot(alldata['Temperature'],ConditionB,linewidth = 1,c='k', label = "ConditonB")
ax.legend(numpoints=1)
plt.show()
【问题讨论】:
-
了解 Fig_1.csv 的样子会有所帮助 (*.com/help/mcve)
-
@Noah 你是对的,这应该是问题的一部分。但由于显然 OP 没有意识到这一点,我在下面的答案中创建了一个 minimal reproducible example,您可以使用它来重现这种情况。
-
@ImportanceOfBeingErnest 你的回答已经超越了你,我为你的好意和有用的回答投了你的票:)
标签: python matplotlib legend