Note that there are some explanatory texts on larger screens.

plurals
  1. POStop pandas plot from doing new x-axis layout
    text
    copied!<p>I have a problem of an automatic x-axis rescaling happening when I do the following:</p> <ol> <li>plot column 1</li> <li>plot column 1 where column 2 is notnull, but with different style.</li> </ol> <p>The second plot keeps rescaling the x-axis for me, losing the overview of the full column 1 plot. I have detailed what happened in this notebook: <a href="http://nbviewer.ipython.org/5596249" rel="nofollow">http://nbviewer.ipython.org/5596249</a></p> <p>Is there a way to keep the x-axis from rescaling at the 2nd plot? I have tried x_compat=True but that does not seem to do anything for me. </p> <p>Versions: pd: 0.11.0, MPL: 1.2.0</p> <p>[Edit] Here's the ipython output:</p> <pre><code>In [1]: import pandas as pd In [2]: pd.__version__ Out[2]: '0.12.0.dev-f354548' 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 17:55:43 -0.440814 0.246620 2013-05-18 17:55:43 -0.732045 -0.896267 2013-05-19 17:55:43 1.131248 1.213163 2013-05-20 17:55:43 0.478372 0.624647 2013-05-21 17:55:43 1.425489 0.396689 2013-05-22 17:55:43 -0.881991 0.322917 2013-05-23 17:55:43 -1.047584 0.154040 2013-05-24 17:55:43 -0.327258 0.944843 2013-05-25 17:55:43 -0.013396 1.045499 2013-05-26 17:55:43 -0.035380 -0.611224 In [6]: df[1][:5]=nan In [7]: df Out[7]: 0 1 2013-05-17 17:55:43 -0.440814 NaN 2013-05-18 17:55:43 -0.732045 NaN 2013-05-19 17:55:43 1.131248 NaN 2013-05-20 17:55:43 0.478372 NaN 2013-05-21 17:55:43 1.425489 NaN 2013-05-22 17:55:43 -0.881991 0.322917 2013-05-23 17:55:43 -1.047584 0.154040 2013-05-24 17:55:43 -0.327258 0.944843 2013-05-25 17:55:43 -0.013396 1.045499 2013-05-26 17:55:43 -0.035380 -0.611224 In [8]: df[0].plot() Out[8]: &lt;matplotlib.axes.AxesSubplot at 0x116dbff50&gt; In [9]: df[1].plot() Out[9]: &lt;matplotlib.axes.AxesSubplot at 0x116dbff50&gt; In [10]: # the above did not rescale the x-axis, even so the plottable range of [1] is smaller In [11]: clf() In [12]: df['selector'] = df[1].notnull() In [13]: df Out[13]: 0 1 selector 2013-05-17 17:55:43 -0.440814 NaN False 2013-05-18 17:55:43 -0.732045 NaN False 2013-05-19 17:55:43 1.131248 NaN False 2013-05-20 17:55:43 0.478372 NaN False 2013-05-21 17:55:43 1.425489 NaN False 2013-05-22 17:55:43 -0.881991 0.322917 True 2013-05-23 17:55:43 -1.047584 0.154040 True 2013-05-24 17:55:43 -0.327258 0.944843 True 2013-05-25 17:55:43 -0.013396 1.045499 True 2013-05-26 17:55:43 -0.035380 -0.611224 True In [14]: df[0].plot() Out[14]: &lt;matplotlib.axes.AxesSubplot at 0x111288250&gt; In [15]: df[df.selector][0].plot(style='r*', markersize=5) Out[15]: &lt;matplotlib.axes.AxesSubplot at 0x111288250&gt; In [16]: # the above rescaled the x-axis </code></pre> <p>and here's just the code:</p> <pre><code>import pandas as pd pd.__version__ dr = pd.date_range('now',periods=10) df = pd.DataFrame(randn(10,2),index=dr) df[1][:5]=nan # This way it works: df[0].plot() df[1].plot() df['selector'] = df[1].notnull() df[0].plot() # This way the x-axis is being rescaled. How can I fix it at the previous setting? df[df.selector][0].plot(style='r*') </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload