Storytelling Data Visualization on Exchange Rates subplot issue

My Code:

ax6 = fig.add_subplot(2,7,7)
ax6.plot(euro_to_dollar['Time'][5484:5697],rolling_mean[5484:5697], 
       color='#24778c', linewidth=2.5)
plt.xlim([datetime.date(2020, 3, 9), datetime.date(2021, 1, 8)])
ax6.xaxis.set_major_locator(mdates.MonthLocator(interval=1))
ax6.xaxis.set_major_formatter(DateFormatter("%Y-%m"))
plt.xticks(rotation = 90)
ax6.set_yticklabels([])

What I expected to happen:

I expected the graph to plot between March, 2020 and January, 2021.

What actually happened:

The plot only starts around June. I know I set my time indices correctly. I have verified that this time interval starts on exactly March 9 so I’m confused why my graph doesn’t reflect that.

# n/a

euro_to_dollar.ipynb (634.9 KB)

The code in question is in line 21.

Click here to view the jupyter notebook file in a new tab

Hi @kylemoorman1

I checked the min and max of this subset euro_to_dollar['Time'][5484:5697] and its something like this:

min(euro_to_dollar['Time'][5484:5697]), max(euro_to_dollar['Time'][5484:5697])

(Timestamp('2020-06-08 00:00:00'), Timestamp('2021-01-08 00:00:00'))

So the data in this subset starts in June.

The index where the year 2020 and the month of march starts is 5479 (at the time of this post. It may change if you apply further filters/ wranglings to your dataset).

euro_to_dollar[(euro_to_dollar['Time'].dt.year == 2020) &
               (euro_to_dollar['Time'].dt.month == 3)]

 	              Time	 US_dollar
5479	2020-03-02	 1.1122

Perhaps recheck the indices you were actually intending to segregate at. I do have to ask you this, why are you slicing your data frame using indices and not the Time column itself, since you already have the intervals you wish to highlight !?

If I remember correctly I have mentioned this as feedback on another project submission for the same topic (sorry if it was a different project :slightly_frowning_face: ).

Let me know if this wasn’t helpful.

By the way, your graphs are beautiful!

Screen Link:

My Code:

ax6 = fig.add_subplot(2,7,7)



ax6.plot(euro_to_dollar['Time'][5484:5697],rolling_mean[5484:5697], 
       color='#24778c', linewidth=2.5)

plt.xlim([datetime.date(2020, 3, 9), datetime.date(2021, 1, 8)])
ax6.xaxis.set_major_locator(mdates.MonthLocator(interval=1))
ax6.xaxis.set_major_formatter(DateFormatter("%Y-%m"))
plt.xticks(rotation = 90)
ax6.set_yticklabels([])
plt.ylim([.8,1.6])

What I expected to happen:

I expected my graph to plot from March-09

What actually happened:

please see output on line 82. The graph is missing the line from March, 2020 to about June, 2020.

I’m confuse why all my other subplots are graphed completely except this one. The code has the exact format and I’ve checked and tested several different ideas here. I’d like to get my graphs totally accurate.

You will have to share the output in your post for others to check it out. Alternatively, you can include your Notebook in your post as well. Here’s a guide that can help you with that.

I would recommend sharing your Notebook in your post so that it’s easier to check out all of your code.

1 Like