Skip to content

Instantly share code, notes, and snippets.

@7yl4r
Created February 17, 2020 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7yl4r/42668fb5c338baea56f1751a0fc610c7 to your computer and use it in GitHub Desktop.
Save 7yl4r/42668fb5c338baea56f1751a0fc610c7 to your computer and use it in GitHub Desktop.
Create donut plot split into 3 sections.
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