otm*_*ger 7 python matplotlib python-2.7
我有一个条形图,包括3个堆叠系列和5个条形图.我想通过改变线条的宽度来突出显示一个单独的条形图(所有3个堆叠元素).
我用以下命令绘制条形图:
mybar = ax.bar(x,Y[:,i],bottom=x,color=colors[i],edgecolor='none',width=wi,linewidth = 0)
bar_handles = np.append(bar_handles,mybar)
Run Code Online (Sandbox Code Playgroud)
我已经处理了我要更改存储在数组中bar_handles的栏,有没有办法在绘制后更改栏edgecolor和linewidth属性?
War*_*ser 10
ax.bar回归Container艺术家; 每一个"艺术家"是一个Rectangle与set_linewidth和set_edgecolor方法.
要更改第二个栏中的设置mybar,您可以执行以下操作:
mybar[1].set_linewidth(4)
mybar[1].set_edgecolor('r')
Run Code Online (Sandbox Code Playgroud)
这是一个脚本,显示如何使用它来更改堆栈的线宽:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1,2,3])
y1 = np.array([3,2.5,1])
y2 = np.array([4,3,2])
y3 = np.array([1,4,1])
width = 0.5
handles = []
b1 = plt.bar(x, y1, color='#2040D0', width=width, linewidth=0)
handles.append(b1)
b2 = plt.bar(x, y2, bottom=y1, color='#60A0D0', width=width, linewidth=0)
handles.append(b2)
b3 = plt.bar(x, y3, bottom=y1+y2, color='#A0D0D0', width=width, linewidth=0)
handles.append(b3)
# Highlight the middle stack.
for b in handles:
b[1].set_linewidth(3)
plt.xlim(x[0]-0.5*width, x[-1]+1.5*width)
plt.xticks(x+0.5*width, ['A', 'B', 'C'])
plt.show()
Run Code Online (Sandbox Code Playgroud)
此脚本创建以下条形图:

我最终这样做了:
\n\nax.axvspan(X1,\n X1+wi,\n ymax=Y2,\n facecolor='none',\n edgecolor='black',\n linewidth=2)\nRun Code Online (Sandbox Code Playgroud)\n\n\xe2\x80\xa6 其中
\n\nX1 = bar_handles[startBlock].get_x()\nwi = bar_handles[startBlock].get_width()\nY2 = ax.transLimits.transform((0,bar_handles[startBlock].get_height()))[1]\nRun Code Online (Sandbox Code Playgroud)\n\n这会在我的栏 \xe2\x80\x94 上产生一个边缘,包括 \xe2\x80\x94 中的所有元素,而元素之间没有水平线。
\n| 归档时间: |
|
| 查看次数: |
14638 次 |
| 最近记录: |