如何在matplotlib python上孵化破碎的_barh?

如何在matplotlib python上孵化破碎的_barh?,python,matplotlib,hatchstyle,Python,Matplotlib,Hatchstyle,我想在matplotlib的Break_barh中使用阴影。我想要的是在不同的颜色的情节有不同的图案填充。我试图添加一本字典,但没有成功,有人知道正确的方法是什么吗? 这是matplotlib网站上的示例代码 “”“ 制作一个“断开”的水平条形图,即有间隙的水平条形图 “”“ 我想为不同的颜色设置不同的图案填充,但这是不可能的: 如果有人能给我一个提示,我将不胜感激。break\u barh不允许设置不同的图案填充。但是,由于断条只是多个单条,因此可以使用不同的图案填充绘制单条 import

我想在matplotlib的Break_barh中使用阴影。我想要的是在不同的颜色的情节有不同的图案填充。我试图添加一本字典,但没有成功,有人知道正确的方法是什么吗? 这是matplotlib网站上的示例代码

“”“ 制作一个“断开”的水平条形图,即有间隙的水平条形图 “”“

我想为不同的颜色设置不同的图案填充,但这是不可能的:


如果有人能给我一个提示,我将不胜感激。

break\u barh
不允许设置不同的图案填充。但是,由于断条只是多个单条,因此可以使用不同的图案填充绘制单条

import matplotlib.pyplot as plt

def brokenhatchbar(xs, y, ax=None, **kw):
    if not ax: ax=plt.gca()
    hatches = kw.pop("hatch", [None]*len(xs))
    facecolors = kw.pop("facecolors", [None]*len(xs))
    edgecolors = kw.pop("edgecolors", [None]*len(xs))
    for i, x in enumerate(xs):
        ax.barh(bottom=y[0], width=x[1], height=y[1], left=x[0],
                facecolor=facecolors[i], edgecolor=edgecolors[i], hatch=hatches[i])

fig, ax = plt.subplots()
brokenhatchbar([(110, 30), (150, 10)], (10, 9), facecolors=['blue','blue'], hatch=['o','////'])
brokenhatchbar([(10, 50), (100, 20), (130, 10)], (20, 9),
               facecolors=('red', 'yellow', 'green'), hatch=('//', 'o', '+'))
ax.set_ylim(5, 35)
ax.set_xlim(0, 200)
ax.set_xlabel('seconds since start')

ax.grid(True)

plt.show()

谢谢,这肯定会解决我的问题。非常感谢。
import matplotlib.pyplot as plt

def brokenhatchbar(xs, y, ax=None, **kw):
    if not ax: ax=plt.gca()
    hatches = kw.pop("hatch", [None]*len(xs))
    facecolors = kw.pop("facecolors", [None]*len(xs))
    edgecolors = kw.pop("edgecolors", [None]*len(xs))
    for i, x in enumerate(xs):
        ax.barh(bottom=y[0], width=x[1], height=y[1], left=x[0],
                facecolor=facecolors[i], edgecolor=edgecolors[i], hatch=hatches[i])

fig, ax = plt.subplots()
brokenhatchbar([(110, 30), (150, 10)], (10, 9), facecolors=['blue','blue'], hatch=['o','////'])
brokenhatchbar([(10, 50), (100, 20), (130, 10)], (20, 9),
               facecolors=('red', 'yellow', 'green'), hatch=('//', 'o', '+'))
ax.set_ylim(5, 35)
ax.set_xlim(0, 200)
ax.set_xlabel('seconds since start')

ax.grid(True)

plt.show()