8000 GitHub · Where software is built
[go: up one dir, main page]

Skip to content
Logit scale doesn't position x/ylabel correctly first draw #11386
Closed
@ImportanceOfBeingErnest

Description

@ImportanceOfBeingErnest

Bug report

Bug summary

Using constrained_layout or tight_layout in conjunction with a logit scale fails or crashes.

Constrained layout:

import matplotlib.pyplot as plt
fig, ax = plt.subplots(constrained_layout=True)

ax.plot([.2,.4,.6,.8],[.2, .4, .5, .9])
ax.set_xscale('logit')

plt.show()

results in a crash of python in Windows. I.e. it shows a pop up saying python needs to be closed because it crashed.

Tight layout

import matplotlib.pyplot as plt
fig, ax = plt.subplots()

ax.plot([.2,.4,.6,.8],[.2, .4, .5, .9])
ax.set_xscale('logit')

fig.tight_layout()
plt.show()

produces a long traceback for a ValueError: cannot convert float NaN to integer.

D:\...\envs\mplgit\lib\site-packages\numpy\core\_methods.py:29: RuntimeWarning: invalid value encountered in reduce
  return umr_minimum(a, axis, None, out, keepdims)
D:\...\envs\mplgit\lib\site-packages\numpy\core\_methods.py:26: RuntimeWarning: invalid value encountered in reduce
  return umr_maximum(a, axis, None, out, keepdims)
posx and posy should be finite values
posx and posy should be finite values
posx and posy should be finite values
posx and posy should be finite values
posx and posy should be finite values
posx and posy should be finite values
posx and posy should be finite values

Traceback (most recent call last):
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\backends\backend_qt5.py", line 513, in _draw_idle
    self.draw()
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\backends\backend_agg.py", line 421, in draw
    self.figure.draw(self.renderer)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\artist.py", line 50, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\figure.py", line 1478, in draw
    renderer, self, artists, self.suppressComposite)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\artist.py", line 50, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\axes\_base.py", line 2583, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\artist.py", line 50, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\axis.py", line 1177, in draw
    ticks_to_draw = self._update_ticks(renderer)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\axis.py", line 1017, in _update_ticks
    tick_tups = list(self.iter_ticks())  # iter_ticks calls the locator
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\axis.py", line 961, in iter_ticks
    majorLocs = self.major.locator()
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\ticker.py", line 1922, in __call__
    return self.tick_values(vmin, vmax)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\ticker.py", line 1930, in tick_values
    locs = self._raw_ticks(vmin, vmax)
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\ticker.py", line 1876, in _raw_ticks
    nbins = np.clip(self.axis.get_tick_space(),
  File "d:\...\python\matplotlib\source\matplotlibgit\matplotlib\lib\matplotlib\axis.py", line 2503, in get_tick_space
    return int(np.floor(length / size))
ValueError: cannot convert float NaN to integer

Expected outcome

Using either of above without layout manager gives the correct figure.

Also, using either of above without the line ax.set_xscale('logit') produces the expected output.

This may be related to #5456.

Matplotlib version

  • Operating system: Windows 8.1
  • Matplotlib version: 2.2.2.post1271+g0a70730fa
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg, TkAgg
  • Python version: 3.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0