#🔒 Adding horisontal bars representing monthly events to time series plot

4 messages · Page 1 of 1 (latest)

opal cloak
#

Hi! I'm working with data related to the Earth's length of day and El Niño/La Niña events. I would like to add horisontal bars at the top or bottom of the time series plot to represent the occurence and duration of El Niño/La Niña events in a similar way to the pictures. I have imported monthly data for El Niño/La Niña occurences and transformed the index to pandas DateTime-format, but I can't figure out how to create this sort of plot. All I've managed to accomplish is

for elnino_date, enso_value in df_elnino_melted.iterrows():
color = 'red' if enso_value['ENSO'] > 0 else 'blue'
plt.axvline(x=elnino_date, color=color, linestyle='--')

but this gives me a bunch of "bars" going across the whole plot vertically, which makes it very messy. Could someone perhaps help me out, either with getting a plot similar to the pictures or to visualize the El Niño/La Niña events in some other easily interpretable and clean way?

graceful havenBOT
#

@opal cloak

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

graceful havenBOT
#

@opal cloak

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.