![](/img/trans.png)
[英]Use shades of the same colour to colour the bars of a plotly bar chart
[英]How to use a float to specify a colour (not grayscale shades)?
您可以通過提供3元(或4元) float
來指定RGB(A)顏色,也可以使用單個float
值從顏色圖中選擇一種顏色:
from matplotlib import pyplot as plt
import numpy as np
x1 = [2, 3, 4]
y1 = [20, 30, 40]
x2 = [-2, -3, -4]
y2 = [-20,-30,-40]
plt.figure(1, figsize=(9, 4))
# Specify a RGB color from float 3-tuple
plt.subplot(1, 2, 1)
plt.plot(x1, y1, '*', c=np.random.rand(3))
plt.plot(x2, y2, 'o', c=np.random.rand(3))
plt.ylabel('RGB color from float 3-tuple')
# Specify a color from a colormap from a single float
plt.subplot(1, 2, 2)
plt.plot(x1, y1, '*', c=plt.cm.viridis(np.random.rand()))
plt.plot(x2, y2, 'o', c=plt.cm.viridis(np.random.rand()))
plt.ylabel('Color from colormap from single float')
plt.tight_layout()
plt.show()
希望有幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.