In [1]:
import pandas as pd
In [2]:
pd.__version__
Out[2]:
'0.11.0'
In [3]:
dr = pd.date_range('now',periods=10)
In [4]:
df = pd.DataFrame(randn(10,2),index=dr)
In [5]:
df
Out[5]:
0 1
2013-05-17 00:42:32 -0.389840 -0.152778
2013-05-18 00:42:32 0.821756 0.208864
2013-05-19 00:42:32 0.486829 -0.034712
2013-05-20 00:42:32 2.252697 0.689548
2013-05-21 00:42:32 -0.022469 0.228613
2013-05-22 00:42:32 -0.133534 0.663756
2013-05-23 00:42:32 -1.021987 -0.339355
2013-05-24 00:42:32 0.533003 0.246249
2013-05-25 00:42:32 2.572123 1.843940
2013-05-26 00:42:32 0.296904 0.019658
In [7]:
df[1][:5]=nan
In [8]:
df
Out[8]:
0 1
2013-05-17 00:42:32 -0.389840 NaN
2013-05-18 00:42:32 0.821756 NaN
2013-05-19 00:42:32 0.486829 NaN
2013-05-20 00:42:32 2.252697 NaN
2013-05-21 00:42:32 -0.022469 NaN
2013-05-22 00:42:32 -0.133534 0.663756
2013-05-23 00:42:32 -1.021987 -0.339355
2013-05-24 00:42:32 0.533003 0.246249
2013-05-25 00:42:32 2.572123 1.843940
2013-05-26 00:42:32 0.296904 0.019658

This way it works:

In [9]:
df[0].plot()
Out[9]:
<matplotlib.axes.AxesSubplot at 0x117ff9e10>
In [10]:
display(gcf())
In [11]:
df[1].plot()
Out[11]:
<matplotlib.axes.AxesSubplot at 0x117ff9e10>
In [12]:
display(gcf())
In [13]:
df['selector'] = df[1].notnull()
In [14]:
df
Out[14]:
0 1 selector
2013-05-17 00:42:32 -0.389840 NaN False
2013-05-18 00:42:32 0.821756 NaN False
2013-05-19 00:42:32 0.486829 NaN False
2013-05-20 00:42:32 2.252697 NaN False
2013-05-21 00:42:32 -0.022469 NaN False
2013-05-22 00:42:32 -0.133534 0.663756 True
2013-05-23 00:42:32 -1.021987 -0.339355 True
2013-05-24 00:42:32 0.533003 0.246249 True
2013-05-25 00:42:32 2.572123 1.843940 True
2013-05-26 00:42:32 0.296904 0.019658 True
In [15]:
df[0].plot()
Out[15]:
<matplotlib.axes.AxesSubplot at 0x118023090>
In [16]:
display(gcf())

This way the x-axis is being rescaled. How can I fix it at the previous setting?

In [17]:
df[df.selector][0].plot(style='r*')
Out[17]:
<matplotlib.axes.AxesSubplot at 0x118023090>
In [18]:
display(gcf())
In []:
 
Back to top