我在python中繪製了一個使用matplotlib的散點圖。我想基於一些功能轉色點,像這樣:基於matplotlib中函數的自定義顏色映射
import matplotlib.pyplot as plt
def color(x, y):
# based on some rules, return a color
if(condition):
return 'red'
else:
return 'blue'
plt.scatter(index, data) #c= something?
我知道了matplotlib.from_levels_and_colors
功能的,但問題是,映射不是基於在x的值的水平或y軸。每個數據點都有一個由函數計算出來的第三個值,這就是我想要基於的顏色點。
有沒有辦法做到這一點?
雖然我沒有最終使用這種方式,但我會接受它,因爲它比我的方式更清潔 – bobroxsox