Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add_subplot with numpy.float64 argument gives error in twinx() #880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
robbertbloem opened this issue May 18, 2012 · 2 comments
Closed

add_subplot with numpy.float64 argument gives error in twinx() #880

robbertbloem opened this issue May 18, 2012 · 2 comments
Assignees

Comments

@robbertbloem
Copy link

I was trying to get two scales, using the example http://matplotlib.sourceforge.net/examples/api/two_scales.html

If you change this:

ax1 = fig.add_subplot(111)

to this:

a = np.float64(1)
ax1 = fig.add_subplot(a,1,1)

I get the error copied below. The problem is that add_subplot() accepts a type that bubble() (called by twinx()) can't handle. Because the error occurs 10 lines later in the code it was particularly difficult to find.

I use the Enthought Python Distribution (free) 7.2-2 (32 bit), Matplotlib 1.1.0 using the WXAgg back end and Numpy 1.6.1 on OS X 10.7.4.

Thanks,

Robbert

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/IPython/utils/py3compat.py in execfile(fname, *where)
    173             else:
    174                 filename = fname
--> 175             __builtin__.execfile(filename, *where)

/xxx/test.py in <module>()
     15 
     16 
---> 17 ax2 = ax1.twinx()
     18 s2 = np.sin(2*np.pi*t)
     19 ax2.plot(t, s2, 'r.')

/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/axes.py in twinx(self)
   7366 
   7367         ax2 = self.figure.add_axes(self.get_position(True), sharex=self,
-> 7368             frameon=False)
   7369         ax2.yaxis.tick_right()
   7370         ax2.yaxis.set_label_position('right')

/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py in add_axes(self, *args, **kwargs)
    705 
    706         self._axstack.add(key, a)
--> 707         self.sca(a)
    708         return a
    709 

/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py in sca(self, a)
   1055     def sca(self, a):
   1056         'Set the current axes to be a and return a'
-> 1057         self._axstack.bubble(a)
   1058         for func in self._axobservers: func(self)
   1059         return a

/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py in bubble(self, a)
     77 
     78     def bubble(self, a):
---> 79         return Stack.bubble(self, self._entry_from_axes(a))
     80 
     81     def add(self, key, a):

/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/cbook.py in bubble(self, o)
   1201         """
   1202 
-> 1203         if o not in self._elements:
   1204             raise ValueError('Unknown element o')
   1205         old = self._elements[:]

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
---------------------------------------------------------------------------
@pelson
Copy link
Member

pelson commented Aug 15, 2012

Confirming.

import matplotlib.pyplot as plt
import numpy as np

ax = plt.subplot(5.5, 1, 1)
ax2 = ax.twinx()

is fine, where

import matplotlib.pyplot as plt
import numpy as np

ax = plt.subplot(np.float64(5.5), 1, 1)
ax2 = ax.twinx()

raises a ValueError

pelson added a commit to pelson/matplotlib that referenced this issue Aug 15, 2012
pelson added a commit to pelson/matplotlib that referenced this issue Apr 12, 2013
pelson added a commit that referenced this issue May 14, 2013
Adds a test for subplot float handling (#880)
@dmcdougall
Copy link
Member

Someone reopen this if I closed this mistakenly. I believe it was resolved by #1092.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants