[英]Scatter plots in Pandas/Pyplot: How to plot by category with different markers
[英]How to give the markers in the pyplot scatter plot a custom RGB color?
我正在使用matplotlib.pyplot庫中的散點函數來可視化3D散點圖中的某些數據。 此功能( 鏈接到文檔 )具有一個名為“ c”的參數,可用於為標記提供特定的顏色。
他們注意到,給'c'的參數可以是存儲在2D數組中的RGB代碼。 但是,當我嘗試下面的代碼時,出現錯誤:“ AttributeError:'list'對象沒有屬性'shape'”。
我的問題:是否可以為散點圖中的標記提供RGB格式的自定義顏色? 如果是的話,我該如何實現呢?
任何幫助將不勝感激。
編輯:解決方案:“ RGB”列表中的值應在0到1而不是0到255的范圍內。
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import csv
RGB = [[255,255,255], [127,127,127], [10,10,10]]
r = []
g = []
b = []
a = 0
i = 0
j = 0
k = 0
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
mark = (".",",","o","v","^","<",">","1","2","3","4","8","s","p","P","*","h","H","+","x","X" ) # tuple for available markers from the matplotlib library
with open ('Color_Measurement_POCNR1_wolkjes.csv', 'r') as csvfile:
plots = csv.reader(csvfile, delimiter = ';')
for row in plots:
if a == 1:
r.append(float(row[6]))
g.append(float(row[7]))
b.append(float(row[8]))
print("j = ", j, "r = ", r[j]," g = ", g[j], " b = ", b[j])
ax.scatter(r[j], g[j], b[j], c= RGB[0], marker = mark[k] , s = 50)
a = 0
j += 1
k += 1
if row[0] == "Mean values":
a += 1
ax.set_xlabel('R Label')
ax.set_ylabel('G Label')
ax.set_zlabel('B Label')
plt.show()
他們注意到,給'c'的參數可以是存儲在2D數組中的RGB代碼。
究竟。 但是,在代碼中使用一維列表。 您可以將此列表封裝在另一個列表中以使其成為2D,
ax.scatter( ..., c= [RGB[0]])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.