簡體   English   中英

是否可以在matplotlib中為edgecolors分配顏色圖?

[英]Is it possible to assign a colourmap for edgecolors in matplotlib?

假設需要根據某個變量更改matplotlib標記的邊緣顏色,是否可以為標記的邊緣顏色分配某種離散的顏色圖? 這類似於通過cmap更改標記的面部顏色。

當使用超出繪圖范圍的箭頭顯示限制時,我似乎無法根據另一個變量來更改箭頭顏色。 例如:在下面的代碼中,箭頭的顏色不會隨z改變。

plt.scatter(x,y, c=z, marker=u'$\u2191$', s=40,cmap=discrete_cmap(4, 'cubehelix') )

您可以使用edgecolors參數分散。

您需要列出顏色列表以供scatter 我們可以使用您選擇的colormapNormalizate實例來執行此操作,以將z函數重新縮放到0-1范圍。

我假設您的discrete_cmap函數類似於此處鏈接的函數。

import matplotlib.pyplot as plt
import matplotlib.colors as colors
import numpy as np

# def discrete_cmap() is omitted here...

# some sample data
x = np.linspace(0,10,11)
y = np.linspace(0,10,11)
z = x+y

# setup a Normalization instance
norm = colors.Normalize(z.min(),z.max())

# define the colormap
cmap = discrete_cmap(4, 'cubehelix')

# Use the norm and cmap to define the edge colours
edgecols = cmap(norm(z))

# Use that with the `edgecolors` argument. Set c='None' to turn off the facecolor
plt.scatter(x,y, edgecolors=edgecols, c = 'None', marker='o', s=40 )

plt.show()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM