8000 add_subplot with numpy.float64 argument gives error in twinx() · Issue #880 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
add_subplot with numpy.float64 argument gives error in twinx() #880
Closed
@robbertbloem

Description

@robbertbloem

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 
6052
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()
---------------------------------------------------------------------------

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0