Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b2bd04

Browse files
authored
Merge pull request#24852 from meeseeksmachine/auto-backport-of-pr-24843-on-v3.6.x
Backport PR#24843 on branch v3.6.x (Show that fill_between and span_where provide similar functionalities.)
2 parents34c4371 +19fe70a commit0b2bd04

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
"""
2-
================
3-
Using span_where
4-
================
2+
========================================================================
3+
Shade regions defined by a logical mask using fill_between or span_where
4+
========================================================================
55
6-
Illustrate some helper functions for shading regions where a logical
7-
mask is True.
8-
9-
See `matplotlib.collections.BrokenBarHCollection.span_where`.
6+
Shade regions where a logical mask is True with `.Axes.fill_between` or with
7+
`matplotlib.collections.BrokenBarHCollection.span_where`.
108
"""
119

1210
importnumpyasnp
@@ -15,23 +13,22 @@
1513

1614

1715
t=np.arange(0.0,2,0.01)
18-
s1=np.sin(2*np.pi*t)
19-
s2=1.2*np.sin(4*np.pi*t)
20-
21-
22-
fig,ax=plt.subplots()
23-
ax.set_title('using span_where')
24-
ax.plot(t,s1,color='black')
25-
ax.axhline(0,color='black',lw=2)
16+
s=np.sin(2*np.pi*t)
2617

27-
collection=collections.BrokenBarHCollection.span_where(
28-
t,ymin=0,ymax=1,where=s1>0,facecolor='green',alpha=0.5)
29-
ax.add_collection(collection)
18+
fig,axs=plt.subplots(2,sharex=True,sharey=True)
19+
foraxinaxs:
20+
ax.plot(t,s,color='black')
21+
ax.axhline(0,color='black')
3022

31-
collection=collections.BrokenBarHCollection.span_where(
32-
t,ymin=-1,ymax=0,where=s1<0,facecolor='red',alpha=0.5)
33-
ax.add_collection(collection)
23+
axs[0].set_title('using fill_between')
24+
axs[0].fill_between(t,1,where=s>0,facecolor='green',alpha=.5)
25+
axs[0].fill_between(t,-1,where=s<0,facecolor='red',alpha=.5)
3426

27+
axs[1].set_title('using span_where')
28+
axs[1].add_collection(collections.BrokenBarHCollection.span_where(
29+
t,ymin=0,ymax=1,where=s>0,facecolor='green',alpha=0.5))
30+
axs[1].add_collection(collections.BrokenBarHCollection.span_where(
31+
t,ymin=-1,ymax=0,where=s<0,facecolor='red',alpha=0.5))
3532

3633
plt.show()
3734

@@ -43,7 +40,7 @@
4340
# The use of the following functions, methods, classes and modules is shown
4441
# in this example:
4542
#
43+
# - `matplotlib.axes.Axes.fill_between`
4644
# - `matplotlib.collections.BrokenBarHCollection`
4745
# - `matplotlib.collections.BrokenBarHCollection.span_where`
4846
# - `matplotlib.axes.Axes.add_collection`
49-
# - `matplotlib.axes.Axes.axhline`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp