Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Matplotlib avoid plotting gaps

I am currently generating the plot below: plot

with this code:

ax = plt.subplots()
ax.plot(intra.to_pydatetime(), data)
plt.title('Intraday Net Spillover')
fig.autofmt_xdate()

where intra.to_pydatetime() is a: <bound method DatetimeIndex.to_pydatetime of <class 'pandas.tseries.index.DatetimeIndex'> [2011-01-03 09:35:00, ..., 2011-01-07 16:00:00] Length: 390, Freq: None, Timezone: None>

So the dates go from 2011-01-03 09:35:00, increments by 5 minutes until 16:00:00, and then jumps to the next day, 2011-01-04 09:35:00 until 2011-01-04 16:00:00, and so on.

How can I avoid plotting the gaps between 16:00:00 and 9:30:00 on the following day? I don't want to see these straight lines.

UPDATE:

I will try this to see if it works.

like image 621
Plug4 Avatar asked Dec 03 '14 08:12

Plug4


People also ask

How do I reduce the gap between subplots?

We can use the plt. subplots_adjust() method to change the space between Matplotlib subplots. The parameters wspace and hspace specify the space reserved between Matplotlib subplots. They are the fractions of axis width and height, respectively.

How do I avoid scientific notation in matplotlib?

MatPlotLib with Python To prevent scientific notation, we must pass style='plain' in the ticklabel_format method.

How do you change the range of a matplotlib plot?

MatPlotLib with Python To change the range of X and Y axes, we can use xlim() and ylim() methods.


1 Answers

Simply set the two values defining the line you don't want to see as NaN (Not a Number). Matplotlib will hide the line between the two values automatically.

Check out this example : http://matplotlib.org/examples/pylab_examples/nan_test.html

like image 166
Overdrivr Avatar answered Sep 28 '22 19:09

Overdrivr