[英]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.