C0 C5 C10 C15 C20 C25 C30 C35 C40 C45 C50
P0 47.943345 44.914156 42.376835 37.2786 39.362123 29.822127 29.629069 24.476678 25.052778 25.912881 24.902693
P1 52.682668 52.690758 41.695393 40.427713 41.858335 35.949049 31.22806 28.764532 44.168688 26.438761 30.69287
P2 83.258359 77.803689 73.910762 58.785376 64.709102 71.70526 43.322047 61.934794 37.209905 40.378957 34.300727
P3 84.759114 71.527146 67.49678 70.464186 70.525976 83.271145 54.537616 66.646541 50.066344 45.546549 36.019721
P4 93.104746 83.602079 99.354394 79.144163 91.973071 70.720547 71.314275 60.390247 77.29477 55.319029 49.143297
P5 118.607862 97.718288 93.90805 79.864234 93.758891 74.889755 72.362807 72.517549 51.188231 82.265352 62.780176
P6 115.568743 113.73798 102.607865 92.834522 87.443449 86.866084 69.150371 82.483823 94.319968 68.883143 58.444044
爲了以x軸爲P0,P1,P2等,Y軸爲C0,C1,C2等和點作爲值..我寫了以下腳本使用自定義刻度標籤繪製矩陣數據
temp = [[random.randint(0,200), random.randint(0,200), random.randint(0,200)], [random.randint(0,200), random.randint(0,200), random.randint(0,200)], [random.randint(0,200), random.randint(0,200), random.randint(0,200)]]
plt.subplot(111)
plt.title("error",fontsize=14)
plt.xlabel("P",fontsize=12)
plt.ylabel("CL",fontsize=12)
plt.grid(True,linestyle='-',color='0.75')
x = ['P0', 'P1','P2']
y = ['C0','C1','C2']
z = temp
# scatter with colormap mapping to z value
plt.scatter(x,y,s=20,c=z, marker = 'o', cmap = cm.jet);
plt.colorbar()
plt.gray()
error = "error-graph.png"
plt.savefig(error, bbox_inches='tight', pad_inches=0.2)
究竟是我犯的錯誤是什麼?我如何構建一個?
'plt.scatter'正在尋找(X,Y)的數值來繪製。你已經給出了它們作爲字符串對的點('P0','C0'),('P1','C1'),('P2','C2')。它不能繪製這個。您應該閱讀[documentation](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter)並查看一些示例。 [示例1](http://matplotlib.org/examples/shapes_and_collections/scatter_demo.html)[示例2](https://stackoverflow.com/questions/17682216/scatter-plot-and-color-mapping-in-蟒蛇/ 17682382#17682382) – wflynny 2014-10-02 16:33:33