2

Using this code

pivoted = df.reset_index(level=0).pivot_table(index='date', 
columns='Speaker', values='raw_score')
resampled = pivoted.rolling(450, min_periods=1).mean()
resampled.plot()

I have produced this graph

However I would like to create a break in the x-axis which will remove some of the data in the middle that I am not interested in displaying. The broken x-axis, would span between 1992-2000 and 2006-2017 (leaving out 2000-2006). Any help would be useful, also if someone has suggestions for better smoothing that would be helpful too!

This question is different than the question that is linked below because my x-axis is a datetime object and is the index of my df 'resampled', which is a pivot table. Here is what my df 'resampled' looks like:

       Speaker    Allison   Cohn    Hoenig   Hubbard   etc...  
       date                                                                     
 1992-03-12       NaN       NaN       NaN       NaN  1.174405     
 1992-05-11       NaN       NaN       NaN       NaN  0.847486      
 1992-05-14       NaN       NaN       NaN       NaN  0.417312 

Python/Matplotlib - Is there a way to make a discontinuous axis?

Graham Streich
  • 874
  • 3
  • 15
  • 31
  • You could use try use interpolation to smooth the graph. https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html –  Oct 06 '17 at 02:12
  • It's not very clear what do you mean by "truncate the x-axis". Do you want two chart with the two periods or do you want to create a break in the x-axis which will remove some of the data in the middle that you are not interested in displaying? – binjip Oct 06 '17 at 02:22
  • I want to `create a break in the x-axis which will remove some of the data in the middle that you are not interested in displaying`. Sorry for the confusion, I will edit the question now. – Graham Streich Oct 06 '17 at 12:08

0 Answers0