没有找到答案。
我的数据看起来像这样:
import pandas as pd
mapDF = pd.DataFrame({u'N1': {0: 20, 1: 20, 2: 20, 3: 20, 4: 20, 5: 21, 6: 21, 7: 21, 8: 21, 9: 21, 10: 22, 11: 22, 12: 22, 13: 22, 14: 22, 15: 23, 16: 23, 17: 23, 18: 23, 19: 23, 20: 24, 21: 24, 22: 24, 23: 24, 24: 24},
u'N2': {0: 50, 1: 51, 2: 52, 3: 53, 4: 54, 5: 50, 6: 51, 7: 52, 8: 53, 9: 54, 10: 50, 11: 51, 12: 52, 13: 53, 14: 54, 15: 50, 16: 51, 17: 52, 18: 53, 19: 54, 20: 50, 21: 51, 22: 52, 23: 53, 24: 54},
u'optGain': {0: 1.119175, 1: 1.11189, 2: 1.0984430000000001, 3: 1.0648280000000001, 4: 1.0459499999999999, 5: 1.149848, 6: 1.154882, 7: 1.1460840000000001, 8: 1.096886, 9: 1.098012, 10: 1.1416869999999999, 11: 1.118763, 12: 1.118763, 13: 1.098276, 14: 1.068576, 15: 1.1165069999999999, 16: 1.128744, 17: 1.128744, 18: 1.1070770000000001, 19: 1.0678430000000001, 20: 1.100743, 21: 1.096325, 22: 1.087421, 23: 1.090177, 24: 1.089968},
u'simGain': {0: 0.94936399999999999, 1: 0.94052000000000002, 2: 0.93819300000000005, 3: 0.90808299999999997, 4: 0.91296299999999997, 5: 0.94936399999999999, 6: 0.90771599999999997, 7: 0.90771599999999997, 8: 0.91296299999999997, 9: 0.85592699999999999, 10: 0.90232000000000001, 11: 0.90232000000000001, 12: 0.84629200000000004, 13: 0.75560000000000005, 14: 0.75560000000000005, 15: 0.92555200000000004, 16: 0.87239299999999997, 17: 0.87274600000000002, 18: 0.88428399999999996, 19: 0.83454799999999996, 20: 0.86954900000000002, 21: 0.88426899999999997, 22: 0.88746899999999995, 23: 0.82285200000000003, 24: 0.82285200000000003}})
我正在尝试制作等高线图或曲面图,其中N1,N2是x,y轴,optGain列是值。 尝试使用pylab或plotlib,但没有一个接受DF,所有都需要对数据进行网格划分。这很麻烦,因为我不打算绘制函数,而是绘制已有的数据。 任何帮助或指示将不胜感激 谢谢!
答案 0 :(得分:1)
查看this question的答案。
一般情况下,您可以使用
执行此操作import matplotlib.pyplot as plt
plt.scatter(mapDF.N1.values, mapDF.N2.values, c=mapDF.optGain.values, s=500)
plt.gray()
plt.show()
它将在连续灰色的价值观中绘制东西。
修改强>
以上将绘制灰度散点图。正如Syrtis Major在评论中所述,请尝试tricontour
获取2d等高线图。使用此功能,请注意colors
参数,具体为:
如果matplotlib颜色的元组args(字符串,浮点数,rgb等),将按指定的顺序以不同的颜色绘制不同的级别。
因此,您可以使用mapDF.optGain.values
为不同级别构建RGB颜色。