图例在Python中无法正常工作

Quazi Nizam

在此处输入图片说明 导入matplotlib.pyplot as plt导入numpy as np导入xlrd导入xlwt导入pandas作为pd

wb = xlrd.open_workbook('Scatter plot.xlsx')

sh1 = wb.sheet_by_name('T180')
sh2=wb.sheet_by_name("T181")
sh3=wb.sheet_by_name("T182")
sh4=wb.sheet_by_name("T183")
sh5=wb.sheet_by_name("T189")

x= np.array([sh1.col_values(1, start_rowx=51, end_rowx=301)])
y= np.array([sh1.col_values(2, start_rowx=51, end_rowx=315)])

x1= np.array(sh2.col_values(1, start_rowx=50, end_rowx=298))
y1= np.array(sh2.col_values(2, start_rowx=50, end_rowx=298))

plt.style.use('ggplot')
fn ="C:\Users\M15-1478\Desktop\python\Scatter plot.xlsx"
sheetname = 'T181'
df = pd.read_excel(fn, sheetname=sheetname, skiprows=47,    parse_cols='B:C').dropna(how='any')
df.ix[df.eval('0 <= GrvX <= 1000'), 'GrvX'] -= 150
df.ix[df.eval('1000 < GrvX <= 2000'), 'GrvX'] -= 50
df.ix[df.eval('2000 < GrvX'), 'GrvX'] -= 30

# customize Y-values
df.ix[df.eval('0 <= GrvY <= 1000'), 'GrvY'] += 30

print df
df.plot(x='GrvX', y='GrvY',  linestyle='no line', marker="o",  label="Corrected T182")
plt.plot(x,y, "gs", label="T181")
plt.plot(x1,y1, "bx", label="T182")
plt.legend(loc=0)
plt.show()

除第一个图例(“更正的T182”)外,图例未正确显示。我尝试了很多方法。我怎么解决这个问题?我在这里附上我有问题的照片。我还附上了数据文件,以方便您使用。提前致谢。资料档案

Quazi Nizam

我发现如果我使用熊猫来读取xls文件,那么图例就没有问题。运行得很好在此处输入图片说明

导入matplotlib.pyplot as plt导入numpy as np导入pandas as pd导入数学导入xlwt导入xlrd

x_180=df_180.iloc[:,7]
y_180=df_180.iloc[:,8]

x_181=df_181.iloc[:,7]
y_181=df_181.iloc[:,8]

x_182=df_182.iloc[:,7]
y_182=df_182.iloc[:,8]

x_183=df_183.iloc[:,7]
y_183=df_183.iloc[:,8]

plt.plot(x_180,y_180,"ro", label="T180")
plt.plot(x_181,y_181,"gs", label="T181")
plt.plot(x_182,y_182,"bx", label="T182")

plt.xlabel("x (micron)", size ="18",color ="m")
plt.ylabel("y (micron)", size ="18",color ="m")
plt.title("Scatter plot of two adjacent detector surfaces after translation", size ="18",color ="m")
plt.legend()
plt.show()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章