Created
February 17, 2020 20:36
-
-
Save 7yl4r/42668fb5c338baea56f1751a0fc610c7 to your computer and use it in GitHub Desktop.
Create donut plot split into 3 sections.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
fig, ax = plt.subplots() | |
size = 0.3 | |
vals = [ | |
25, | |
50, | |
75 | |
] | |
LABELS = [ | |
"coral health index", | |
"reef health index", | |
"other helath index" | |
] | |
normalized_vals = [] | |
labels = [] | |
for i in range(len(vals)): | |
v = vals[i]*33/100 | |
normalized_vals.append(v) | |
normalized_vals.append(33 - v) | |
labels.append(str(vals[i]) + "%") | |
labels.append(' ') | |
cmap = plt.get_cmap("tab20c") | |
inner_colors = cmap(np.array([1, 2, 5, 6, 9, 10])) | |
ax.pie( | |
normalized_vals, radius=1-size, colors=inner_colors, | |
wedgeprops=dict(width=size, edgecolor='w'), | |
labels=labels | |
) | |
ax.set(aspect="equal", title='Health indicies') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment