散点图上的彩色地图

时间:2016-03-28 14:00:55

标签: python matplotlib plot plotly colorbrewer

我在csv文件中有三列,其内容如下:

X,Y, Cosine efficiency
989.565,670.17,0.868684456
660.941,-1502.48,0.597998523
685.683,-1491.35,0.600137189
-1454.88,-316.582,0.666894492
-510.86,1016.79,0.870398677
-1350.21,-788.027,0.61601682
-944.034,-1342.79,0.565497692
-966.098,-1327,0.56678693
-1206.4,-1054.63,0.590095562
1004.18,648.067,0.866589585

我可以通过以下方式读取X和Y值并制作散点图:

import csv
# Reading data from csv file
with open('my_file.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
    X = []
    Y = []
    C = []

for row in readCSV:
    X_coordinates = row[0]
    Y_coordinates = row[1]
    cos_eff = row[2]
    X.append(X_coordinates)
    Y.append(Y_coordinates)
    C.append(cos_eff)
Xcoordinate = [float(X[c]) for c in range(1,len(X))]
Ycoordinate=[float(Y[c]) for c in range(1,len(Y))]
CosineEff=[float(C[c]) for c in range(1,len(C))]

# Plotting the solar field
plt.figure(1)
plt.scatter(Xcoordinate,Ycoordinate, color = 'blue', s=2)
plt.title("Solar field")
plt.xlabel("Position, east-west [m]"); plt.ylabel("Position, east-west [m]")
plt.show()

现在,我想使用使用第三列中的值的颜色映射来制作此散点图。

例如,第一点是:989.565,670.17,0.868684456。我已经绘制了X和Y坐标 - 在本例中为989.565和670.17。但我想使用颜色贴图将值0.868684456放在这个绘制的X& Y值。

我想使用Brewer2mpl或pcolour,但我不知道从哪里开始。

我可以使用'color mapped'函数在Origin上制作一个颜色贴图但是我怎么能在Python上做呢?

1 个答案:

答案 0 :(得分:1)

plt.scatter(x_vals, y_vals,  c = z_vals, cmap = 'rainbow')

你想要添加s =并为这些点选择合适的大小。还有一个漂亮的colormap set called cmocean,您可能需要考虑安装