Skip to content

parasite axis2 demo now crashes with log x-axis #12208

Closed
@lupien

Description

@lupien

Bug report

Bug summary

The code from the Parasite Axes2 demo crashes when the x-axis is turned to a logarithmic scale.
This problem is new in the 2.2 branch.

Code for reproduction
Execute the code from Demo Parasite Axes2
https://matplotlib.org/gallery/axisartist/demo_parasite_axes2.html
This will work correctly.
Then set the x scale to log (before the show):

  plt.xlim(.1)
  plt.xscale('log')

Now the program will produce many errors.

Actual outcome

Traceback (most recent call last):
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 519, in _draw_idle
    self.draw()
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 433, in draw
    self.figure.draw(self.renderer)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/figure.py", line 1475, in draw
    renderer, self, artists, self.suppressComposite)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
    a.draw(renderer)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/mpl_toolkits/axes_grid1/parasite_axes.py", line 286, in draw
    self._get_base_axes_attr("draw")(self, renderer)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/mpl_toolkits/axisartist/axislines.py", line 756, in draw
    super(Axes, self).draw(renderer, inframe)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 2607, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
    a.draw(renderer)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/mpl_toolkits/axisartist/axis_artist.py", line 1479, in draw
    self._draw_ticks(renderer)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/mpl_toolkits/axisartist/axis_artist.py", line 1211, in _draw_ticks
    self.major_ticks.draw(renderer)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/mpl_toolkits/axisartist/axis_artist.py", line 330, in draw
    locs = path_trans.transform_non_affine([loc])
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/transforms.py", line 2489, in transform_non_affine
    return self._a.transform_non_affine(points)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/transforms.py", line 2263, in transform_non_affine
    x_points = x.transform_non_affine(points)[:, 0:1]
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/transforms.py", line 2489, in transform_non_affine
    return self._a.transform_non_affine(points)
  File "/opt/anaconda2/envs/py2_conda52/lib/python2.7/site-packages/matplotlib/transforms.py", line 2265, in transform_non_affine
    x_points = x.transform_non_affine(points[:, 0])
TypeError: list indices must be integers, not tuple

Expected outcome
There should be no errors.

Matplotlib version

  • Operating system: linux and windows
  • Matplotlib version: 2.2.2
  • Matplotlib backend: Qt5Agg
  • Python version: 2.7.15

Installed with conda (anaconda=5.2 python=2).
Same problem with python 3.6.5.
Problem is probably there in 3.0.0 but I have not tested that.

Note that it used to work without errors with anaconda 5.1 (matplotlib=2.1.2).

Possible fix
The problem is probably because of commit ffb5461

I can fix it by changing line 330 in mpl_toolkits/axisartist/axis_artist.py (methode draw of Ticks) from
locs = path_trans.transform_non_affine([loc])
to
locs = path_trans.transform_non_affine(np.array([loc]))

Another option would be to NOT use numpy indexing in transform_non_affine of BlendedGenericTransform of matplotlib/transforms.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions