如何孵化PolyCollection实例? [英] How to hatch PolyCollection instance?
本文介绍了如何孵化PolyCollection实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以孵化 PolyCollection 实例?我想从 fill_betweenx 返回一个 PolyCollection.
Is it possible to hatch PolyCollection instance? I want to hath a PolyCollection returned from fill_betweenx.
import matplotlib.mlab as mlab
from matplotlib.pyplot import figure, show
import numpy as np
x = np.arange(0.0, 2, 0.01)
y1 = np.sin(2*np.pi*x)
y2 = 1.2*np.sin(4*np.pi*x)
fig = figure()
ax1 = fig.add_subplot(111)
PC = ax1.fill_betweenx(x, 0, y1)
# I want to do something like this
# PC.set_hatch('\')
# but there is no such method
show()
推荐答案
有点麻烦,但是您应该可以执行以下操作:
It's a bit of a hack, but you should be able to do something like this:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import PathPatch
x = np.arange(0.0, 2, 0.01)
y1 = np.sin(2*np.pi*x)
y2 = 1.2*np.sin(4*np.pi*x)
fig, ax = plt.subplots()
pc = ax.fill_betweenx(x, 0, y1, color='blue')
# Now we'll add the hatches...
for path in pc.get_paths():
patch = PathPatch(path, hatch='/', facecolor='none')
ax.add_patch(patch)
plt.show()
这篇关于如何孵化PolyCollection实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文