As you can see the blue vertical lines indicate borders set by multiples of standard deviations. I would like to add the following information and color coding, which I now quickly placed in powerpoint:
I tried to mess with the plt.fill_between
function but didnt really get anything useful. Also I do not know how to write something, like the mu l*sigma here, above the plot. How can i achieve the second picture based on what I have?
EDIT: solved by @Trenton McKinney
Putting new boxes inside the colored boxes:
for i, (x, c) in enumerate(locs[:-1]):
axes.axvspan(x, locs[i 1][0], alpha=0.2, color=c)
tx = (x locs[i 1][0]) / 2
axes.text(tx, y1/2, f'Zustand {i 1}', {'ha': 'center', 'va': 'center'}, rotation=90)
if i<4:
axes.text(tx, y1/1.25, r"$\mu$" "-" f"{4-i}" "$\cdot$" "$\sigma$" , {'ha': 'center', 'va': 'center'}, rotation=90, bbox=dict(facecolor='white', alpha=0.8, edgecolor='black'))
else:
axes.text(tx, y1/1.25, r"$\mu$" " " f"{i-4 1}" "$\cdot$" "$\sigma$" , {'ha': 'center', 'va': 'center'}, rotation=90, bbox=dict(facecolor='white', alpha=0.8, edgecolor='black'))
CodePudding user response:
- It will be easier to create a container with all of the values for the vertical lines because those values will be reused for placing the lines, and determining the
axvspan
andtext
placement. In this case, a dictionary is used. - See inline notation for explanations
- Use
Update for additional annotations
# extra annotations sign = [f'µ - {v}σ' for v in range(4, 0, -1)] sigp = [f'µ {v}σ' for v in range(1, 5)] anno = sign sigp # iterate through all but the last value and add the vspan and the text for i, (x, c) in enumerate(locs[:-1]): axes.axvspan(x, locs[i 1][0], alpha=0.2, color=c) tx = (x locs[i 1][0]) / 2 axes.text(tx, y1/2, f'Stage {i 1}: {anno[i]}', {'ha': 'center', 'va': 'center'}, rotation=90)