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

Commitca8f098

Browse files
authored
Merge pull request#29499 from meeseeksmachine/auto-backport-of-pr-29488-on-v3.10.0-doc
Backport PR#29488 on branch v3.10.0-doc (DOC: Update broken_barh example)
2 parents9b12c0f +e6bc47f commitca8f098

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

‎galleries/examples/lines_bars_and_markers/broken_barh.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
"""
2-
===========
3-
BrokenBarh
4-
===========
2+
======================
3+
Brokenhorizontal bars
4+
======================
55
6-
Make a "broken" horizontal bar plot, i.e., one with gaps
6+
`~.Axes.broken_barh` creates sequences of horizontal bars. This example shows
7+
a timing diagram.
78
"""
89
importmatplotlib.pyplotasplt
10+
importnumpyasnp
11+
12+
# data is a sequence of (start, duration) tuples
13+
cpu_1= [(0,3), (3.5,1), (5,5)]
14+
cpu_2=np.column_stack([np.linspace(0,9,10),np.full(10,0.5)])
15+
cpu_3=np.column_stack([10*np.random.random(61),np.full(61,0.05)])
16+
cpu_4= [(2,1.7), (7,1.2)]
17+
disk= [(1,1.5)]
18+
network=np.column_stack([10*np.random.random(10),np.full(10,0.05)])
919

10-
# Horizontal bar plot with gaps
1120
fig,ax=plt.subplots()
12-
ax.broken_barh([(110,30), (150,10)], (10,9),facecolors='tab:blue')
13-
ax.broken_barh([(10,50), (100,20), (130,10)], (20,9),
14-
facecolors=('tab:orange','tab:green','tab:red'))
15-
ax.set_ylim(5,35)
16-
ax.set_xlim(0,200)
17-
ax.set_xlabel('seconds since start')
18-
ax.set_yticks([15,25],labels=['Bill','Jim'])# Modify y-axis tick labels
19-
ax.grid(True)# Make grid lines visible
20-
ax.annotate('race interrupted', (61,25),
21-
xytext=(0.8,0.9),textcoords='axes fraction',
22-
arrowprops=dict(facecolor='black',shrink=0.05),
23-
fontsize=16,
24-
horizontalalignment='right',verticalalignment='top')
21+
# broken_barh(xranges, (ymin, height))
22+
ax.broken_barh(cpu_1, (5.8,0.4))
23+
ax.broken_barh(cpu_2, (4.8,0.4))
24+
ax.broken_barh(cpu_3, (3.8,0.4))
25+
ax.broken_barh(cpu_4, (2.8,0.4))
26+
ax.broken_barh(disk, (1.8,0.4),color="tab:orange")
27+
ax.broken_barh(network, (0.8,0.4),color="tab:green")
28+
ax.set_xlim(0,10)
29+
ax.set_yticks([6,5,4,3,2,1],
30+
labels=["CPU 1","CPU 2","CPU 3","CPU 4","disk","network"])
31+
ax.set_title("Resource usage")
2532

2633
plt.show()
2734

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp