散点图上的颜色图 [英] Colour Map on scatter plot
问题描述
我在csv文件中有三列,内容如下:
I have three columns in a csv file which reads like this:
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值并绘制散点图:
I can read the X and Y values and make a scatter plot in the following way:
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()
现在,我要使用使用第三列中的值的色图制作此散点图.
Now, I want to make this scatter plot using a colour map which uses the values from the third column.
例如,第一点是:989.565,670.17,0.868684456.我已经绘制了X和Y坐标-在这种情况下为989.565和670.17.但是我想使用颜色图将0.868684456的值放在此绘制的X& X中. Y值.
For example, the first point is : 989.565,670.17,0.868684456. I have already plotted the X and Y coordinates - in this case 989.565 and 670.17. But i want to use a colour map to put the value of 0.868684456 on this plotted X & Y value.
我想使用Brewer2mpl或pcolour,但我不知道从哪里开始.
I want to use Brewer2mpl or pcolour but I dont know where to start.
我可以使用颜色映射"功能在Origin上进行颜色映射,但是如何在Python上完成呢?
I can make a colour map on Origin using the 'colour mapped' function but how can I do it on Python?
推荐答案
plt.scatter(x_vals, y_vals, c = z_vals, cmap = 'rainbow')
您将要添加s =并为这些点选择适当的大小.您可能还需要考虑一个漂亮的颜色映射集,称为cmocean 安装
You're going to want to play with adding s= and choosing an appropriate size for the points. There's also a beautiful colormap set called cmocean that you may want to consider installing
这篇关于散点图上的颜色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!