1

I'm trying to plot columns of a dataframe. There are 9 columns in the DF (the first being the days of the current week, and four pairs of columns after that - each pair representing total_sessions and average session duration.

The first pair of session-data columns is for the current week, the next pair for the previous week, next for the week ending two weeks ago, and the final pair of columns for week ending three weeks ago. I am trying to create two plots, the first for the four weeks of total_sessions data and the second for the four weeks of average session_duration data. Lets call these Plot 1 and Plot2

The python code for plotting Plot 1 and Plot2 using pandas DataFrame.plot is as follows:

#PLOT1: CURR WEEK DAILY TOTAL SESSIONS AND ALSO LAST 3 WEEKS
# gca stands for 'get current axis'
ax = plt.gca()

df_CurrWeekiOSDailySessionCountDuration.plot(kind='line',x='SESSION_DATE',y='IOS_TOTAL_SESSIONS',ax=ax)
df_CurrWeekiOSDailySessionCountDuration.plot(kind='line',x='SESSION_DATE',y='WM1_IOS_TOTSESSN', color='red', ax=ax)
df_CurrWeekiOSDailySessionCountDuration.plot(kind='line',x='SESSION_DATE',y='WM2_IOS_TOTSESSN', color='green', ax=ax)
df_CurrWeekiOSDailySessionCountDuration.plot(kind='line',x='SESSION_DATE',y='WM3_IOS_TOTSESSN', color='cyan', ax=ax)

plt.show()
plt.savefig("iOSWOWAvgDailySessionCount.png")



#PLOT2: CURR WEEK DAILY AVERAGE SESSION  DURATION AND ALSO LAST 3 WEEKS
ax2 = plt.gca()
df_CurrWeekiOSDailySessionCountDuration.plot(kind='line',x='SESSION_DATE',y='IOS_AVG_SESSION_DURATION',ax=ax2)
df_CurrWeekiOSDailySessionCountDuration.plot(kind='line',x='SESSION_DATE',y='WM1_IOS_AVSESDUR', color='red', ax=ax2)
df_CurrWeekiOSDailySessionCountDuration.plot(kind='line',x='SESSION_DATE',y='WM2_IOS_AVSESDUR', color='green', ax=ax2)
df_CurrWeekiOSDailySessionCountDuration.plot(kind='line',x='SESSION_DATE',y='WM3_IOS_AVSESDUR', color='cyan', ax=ax2)

plt.show()
plt.savefig("iOSWOWAvgDailySessionDuration.png")

The dataframe has the correct data (as printed below)

enter image description here

However the code just creates the first plot successfully. For the second plot it gives me a "no numeric data to plot" error (see below)

enter image description here

Appreciate any help or pointers on what I am doing wrong/how to fix this.

8
  • 3
    Does this answer your question? Saving a figure after invoking pyplot.show() results in an empty file Commented Feb 7, 2020 at 21:08
  • thanks for the tip. unfortunately not. I deferred using the show as suggested on that post, but I still get a blank second plot. When I try plotting the second plot first, it still does not show - and I see this error (perhaps related?) "from_bounds() argument after * must be an iterable, not float" (I also did a round(0) on the entire dataframe to ensure that all values are int but still no luck. Commented Feb 11, 2020 at 20:26
  • The second plot appears to be picking up incorrect values. The y axis should represent average session duration which ranges from 400 to 750 whereas the y axis in the blank plot ranges from 0 to 1. Likewise the X axis (supposed to be date) again is 0 to 1. Commented Feb 12, 2020 at 2:47
  • Even when I comment out the first plot I see the same problem. Commented Feb 12, 2020 at 2:49
  • Did you check your df columns type, there should be no object or str type: df_CurrWeekiOSDailySessionCountDuration.dtypes. Commented Feb 12, 2020 at 6:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.