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

Commit92aa1a3

Browse files
committed
DOC: Update broken_barh example
IMHO this is more realistic and better looking.I've always been wondering what the previous plot should mean.Note: There's precedence for a similar special-casing on polar Axes for errorbars:https://github.com/matplotlib/matplotlib/blob/3fb9c0961b5c8d5753c88ac37c08cda58a4b7839/lib/matplotlib/axes/_axes.py#L3798
1 parent3fb9c09 commit92aa1a3

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

‎galleries/examples/lines_bars_and_markers/broken_barh.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
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. These are for example
7+
used for timing diagrams.
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+
ax.broken_barh(cpu_1, (5.8,0.4))
22+
ax.broken_barh(cpu_2, (4.8,0.4))
23+
ax.broken_barh(cpu_3, (3.8,0.4))
24+
ax.broken_barh(cpu_4, (2.8,0.4))
25+
ax.broken_barh(disk, (1.8,0.4),color="tab:orange")
26+
ax.broken_barh(network, (0.8,0.4),color="tab:green")
27+
ax.set_xlim(0,10)
28+
ax.set_yticks([6,5,4,3,2,1],
29+
labels=["CPU 1","CPU 2","CPU 3","CPU 4","disk","network"])
30+
ax.set_title("Resource usage")
2531

2632
plt.show()
2733

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp