[英]Inclined Bars in Python Bar chart
我有一個用python創建的簡單條形圖,我只想使條形傾斜,不應更改x和y軸,但不知道該怎么做。 可能有這樣的財產?
import matplotlib.pyplot as plt
plt.bar(y_pos, performance, width, fill=False, ,align='center', linewidth = linewidth, alpha=0.6, color = 'gray')
plt.xticks(y_pos, words)
plt.yticks([])
這是您想要獲得的嗎?
import math
def tilt_rectangle(rect, angle=math.pi/4):
verts = p.axes.transData.inverted().transform(rect.get_verts())
verts[2,0] += p.get_height()*math.tan(angle)
verts[3,0] += p.get_height()*math.tan(angle)
poly = matplotlib.patches.Polygon(verts)
p.axes.add_artist(poly)
poly.update_from(rect)
return poly
x = np.arange(4)
y = np.random.random(size=(4,))
fig, ax = plt.subplots()
b = plt.bar(x, y)
for p in b.patches:
poly = tilt_rectangle(p)
poly.set_clip_on(False)
p.remove()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.