我將是填充不同梯度酷似這裏做(不與matplotlib據我瞭解)一barplot的matplotlib/seaborn酒吧很感興趣: 如何用漸變填充matplotlib欄?
我還檢查此相關的主題Pyplot: vertical gradient fill under curve?。
我將是填充不同梯度酷似這裏做(不與matplotlib據我瞭解)一barplot的matplotlib/seaborn酒吧很感興趣: 如何用漸變填充matplotlib欄?
我還檢查此相關的主題Pyplot: vertical gradient fill under curve?。
我使用seaborn barplot與palette
選項。
df = pd.DataFrame({'a':[1,2,3,4,5], 'b':[10,5,2,4,5]})
使用seaborn:
sns.barplot(df['a'], df['b'], palette='Blues_d')
可以獲得類似:像想象一下,你有一個簡單的數據幀
那麼你也可以用palette
選項玩, colormap
根據像一些數據相加的梯度:
sns.barplot(df['a'], df['b'], palette=cm.Blues(df['b']*10)
獲得:
希望有所幫助。
正如在Pyplot: vertical gradient fill under curve?描繪的一個可使用圖像來創建梯度曲線。
由於杆是矩形的圖像的程度,可直接設置到欄的位置和大小。人們可以遍歷所有酒吧並在相應的位置創建圖像。結果是一個梯度條形圖。
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
bar = ax.bar([1,2,3,4,5,6],[4,5,6,3,7,5])
def gradientbars(bars):
grad = np.atleast_2d(np.linspace(0,1,256)).T
ax = bars[0].axes
lim = ax.get_xlim()+ax.get_ylim()
for bar in bars:
bar.set_zorder(1)
bar.set_facecolor("none")
x,y = bar.get_xy()
w, h = bar.get_width(), bar.get_height()
ax.imshow(grad, extent=[x,x+w,y,y+h], aspect="auto", zorder=0)
ax.axis(lim)
gradientbars(bar)
plt.show()
非常感謝,但是我正在尋找相同的梯度每一個酒吧內,沒有一個梯度翻過不同吧! – cattt84