Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matplotlib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Frank Sauerburger
matplotlib
Commits
70df2995
Commit
70df2995
authored
6 years ago
by
Paul J. Koprowski
Browse files
Options
Downloads
Patches
Plain Diff
initial commit, fixes to formatting and squashing of commits
parent
8a8c881c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.flake8
+1
-0
1 addition, 0 deletions
.flake8
examples/pie_and_polar_charts/bar_of_pie.py
+92
-0
92 additions, 0 deletions
examples/pie_and_polar_charts/bar_of_pie.py
with
93 additions
and
0 deletions
.flake8
+
1
−
0
View file @
70df2995
...
...
@@ -182,6 +182,7 @@ per-file-ignores =
examples/misc/table_demo.py: E201
examples/mplot3d/voxels.py: E501
examples/mplot3d/wire3d_zero_stride.py: E501
examples/pie_and_polar_charts/bar_of_pie.py: E402
examples/pie_and_polar_charts/nested_pie.py: E402
examples/pie_and_polar_charts/pie_and_donut_labels.py: E402
examples/pie_and_polar_charts/pie_demo2.py: E402
...
...
This diff is collapsed.
Click to expand it.
examples/pie_and_polar_charts/bar_of_pie.py
0 → 100644
+
92
−
0
View file @
70df2995
"""
==========
Bar of pie
==========
Make a
"
bar of pie
"
chart where the first slice of the pie is
"
exploded
"
into a bar chart with a further breakdown of said slice
'
s
characteristics. The example demonstrates using a figure with multiple
sets of axes and using the axes patches list to add two ConnectionPatches
to link the subplot charts.
"""
import
matplotlib.pyplot
as
plt
from
matplotlib.patches
import
ConnectionPatch
import
numpy
as
np
# make figure and assign axis objects
fig
=
plt
.
figure
(
figsize
=
(
9
,
5.0625
))
ax1
=
fig
.
add_subplot
(
121
)
ax2
=
fig
.
add_subplot
(
122
)
fig
.
subplots_adjust
(
wspace
=
0
)
# pie chart parameters
ratios
=
[.
27
,
.
56
,
.
17
]
labels
=
[
'
Approve
'
,
'
Disapprove
'
,
'
Undecided
'
]
explode
=
[
0.1
,
0
,
0
]
# rotate so that first wedge is split by the x-axis
angle
=
-
180
*
ratios
[
0
]
ax1
.
pie
(
ratios
,
autopct
=
'
%1.1f%%
'
,
startangle
=
angle
,
labels
=
labels
,
explode
=
explode
)
# bar chart parameters
xpos
=
0
bottom
=
0
ratios
=
[.
33
,
.
54
,
.
07
,
.
06
]
width
=
.
2
colors
=
[[.
1
,
.
3
,
.
5
],
[.
1
,
.
3
,
.
3
],
[.
1
,
.
3
,
.
7
],
[.
1
,
.
3
,
.
9
]]
for
j
in
range
(
len
(
ratios
)):
height
=
ratios
[
j
]
ax2
.
bar
(
xpos
,
height
,
width
,
bottom
=
bottom
,
color
=
colors
[
j
])
ypos
=
bottom
+
ax2
.
patches
[
j
].
get_height
()
/
2
bottom
+=
height
ax2
.
text
(
xpos
,
ypos
,
"
%d%%
"
%
(
ax2
.
patches
[
j
].
get_height
()
*
100
),
ha
=
'
center
'
)
ax2
.
set_title
(
'
Age of approvers
'
)
ax2
.
legend
((
'
50-65
'
,
'
Over 65
'
,
'
35-49
'
,
'
Under 35
'
))
ax2
.
axis
(
'
off
'
)
ax2
.
set_xlim
(
-
2.5
*
width
,
2.5
*
width
)
# use ConnectionPatch to draw lines between the two plots
# get the wedge data
theta1
,
theta2
=
ax1
.
patches
[
0
].
theta1
,
ax1
.
patches
[
0
].
theta2
center
,
r
=
ax1
.
patches
[
0
].
center
,
ax1
.
patches
[
0
].
r
bar_height
=
sum
([
item
.
get_height
()
for
item
in
ax2
.
patches
])
# draw top connecting line
x
=
r
*
np
.
cos
(
np
.
pi
/
180
*
theta2
)
+
center
[
0
]
y
=
np
.
sin
(
np
.
pi
/
180
*
theta2
)
+
center
[
1
]
con
=
ConnectionPatch
(
xyA
=
(
-
width
/
2
,
bar_height
),
xyB
=
(
x
,
y
),
coordsA
=
"
data
"
,
coordsB
=
"
data
"
,
axesA
=
ax2
,
axesB
=
ax1
)
con
.
set_color
([
0
,
0
,
0
])
con
.
set_linewidth
(
4
)
ax2
.
add_artist
(
con
)
# draw bottom connecting line
x
=
r
*
np
.
cos
(
np
.
pi
/
180
*
theta1
)
+
center
[
0
]
y
=
np
.
sin
(
np
.
pi
/
180
*
theta1
)
+
center
[
1
]
con
=
ConnectionPatch
(
xyA
=
(
-
width
/
2
,
0
),
xyB
=
(
x
,
y
),
coordsA
=
"
data
"
,
coordsB
=
"
data
"
,
axesA
=
ax2
,
axesB
=
ax1
)
con
.
set_color
([
0
,
0
,
0
])
ax2
.
add_artist
(
con
)
con
.
set_linewidth
(
4
)
plt
.
show
()
#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
import
matplotlib
matplotlib
.
axes
.
Axes
.
pie
matplotlib
.
axes
.
Axes
.
bar
matplotlib
.
pyplot
matplotlib
.
patches
.
ConnectionPatch
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment