[matplotlib-devel] autofmt_xdate() broken for twinx()

2010-11-18 Thread Scott Sinclair
Hi,

It seems that the autofmt_xdate helper method is broken when twinx is
used. Consider the script below:

-
import datetime as dt

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.dates import date2num

strt = dt.datetime(2000, 3, 15, 6)
delta = dt.timedelta(hours=6)
date_list = [(strt + i*delta) for i in range(100)]

x = date2num(date_list)
y = np.sin(x)
z = np.cos(x)

fig, ax1 = plt.subplots()

ax1.plot(date_list, y, 'b-')

ax2 = ax1.twinx()
ax2.plot(date_list, z, 'r-')

# using the auto format method doesn't work
fig.autofmt_xdate()

plt.show()
-

This is because the 'is_last_row' attribute isn't present on ax2 and
len(fig.axes) != 1 when the autofmt_xdate method is called on fig.

The attached patch fixes it for me and still seems to give the
advertised behaviour for single and vertically stacked subplots.

Cheers,
Scott
Index: lib/matplotlib/figure.py
===
--- lib/matplotlib/figure.py	(revision 8806)
+++ lib/matplotlib/figure.py	(working copy)
@@ -312,25 +312,17 @@
 *ha*
 the horizontal alignment of the xticklabels
 """
-allsubplots = np.alltrue([hasattr(ax, 'is_last_row') for ax in self.axes])
-if len(self.axes)==1:
-for label in ax.get_xticklabels():
-label.set_ha(ha)
-label.set_rotation(rotation)
-else:
-if allsubplots:
-for ax in self.get_axes():
-if ax.is_last_row():
-for label in ax.get_xticklabels():
-label.set_ha(ha)
-label.set_rotation(rotation)
-else:
-for label in ax.get_xticklabels():
-label.set_visible(False)
-ax.set_xlabel('')
+for ax in self.get_axes():
+if hasattr(ax, 'is_last_row') and ax.is_last_row():
+for label in ax.get_xticklabels():
+label.set_ha(ha)
+label.set_rotation(rotation)
+else:
+for label in ax.get_xticklabels():
+label.set_visible(False)
+ax.set_xlabel('')
 
-if allsubplots:
-self.subplots_adjust(bottom=bottom)
+self.subplots_adjust(bottom=bottom)
 
 def get_children(self):
 'get a list of artists contained in the figure'
--
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] autofmt_xdate() broken for twinx()

2010-11-23 Thread Scott Sinclair
On 22 November 2010 19:01, Benjamin Root  wrote:
> On Thu, Nov 18, 2010 at 8:58 AM, Scott Sinclair
>  wrote:
>>
>> It seems that the autofmt_xdate helper method is broken when twinx is
>> used.
>>
>> The attached patch fixes it for me and still seems to give the
>> advertised behaviour for single and vertically stacked subplots.
>
> I am not very familiar with this part of mpl, but your diff seems to cut out
> a few things.  In particular, the original code checks to see if the figure
> has a single axes object or more.  However, your code seems to cut this
> check out.  Now, it may have been that the check could have been
> unnecessary, but I am not sure.  I am curious as to your insight on this.

I'm not very familiar with the Matplotlib classes either, but I'll
explain my reasoning.

Anytime I create a figure with a single axes object the axes object
has an is_last_row method which always returns True. I don't see much
point in special casing, unless there's significant overhead that can
be avoided by doing so?

> In addition, the original code called "self.subplots_adjust(bottom=bottom)"
> only when all subplots were on the last row.  Now, it seems that it is
> always called no matter what.

The hasattr test is only checking that each axes object in the figure
has an is_last_row method. In the current code all_subplots is always
True unless the figure contains an axes object created with twinx or
twiny (in which case the autofmt_xdate method does nothing useful -
hence my patch).

Cheers,
Scott

--
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Location of bleeding edge repository

2011-03-08 Thread Scott Sinclair
On 8 March 2011 09:40, Paul Hobson  wrote:
> Is it in git or svn? I just cloned and installed from git using:
> git clone git://github.com/astraw/matplotlib.git
> cd matplotlib
> sudo python setupegg.py develop
>
> Starting ipython, and importing matplotlib, I get:
> In [2]: matplotlib.__version__
> Out[2]: '1.0.0'
>
> I thought v1.0.1 was available. Should I install from svn?

The main repository is at https://github.com/matplotlib/matplotlib you
cloned a forked copy by mistake.

> As an aside, I first tried the proceedure outlined here:
> http://matplotlib.sourceforge.net/devel/coding_guide.html#using-git
> and got a public key error.

That doc appears to be out of date. The repository move was quite recent.

Cheers,
Scott

--
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel