Skip to content

Log Scale: FloatingPointError: underflow encountered in power #15331

Closed
@ptoews

Description

@ptoews

Bug report

Bug summary

When setting the scale to log on an empty axis while having numpy error handling set to raise, a FloatingPointError is thrown. When plotting data beforehand, everything works fine.

This is an issue for me, because I'm trying to plot multiple subplots with shared y axes after each other, where this issue occurs as well. For some reason in that context the error handling seems to bet set to raise.

Issue #4285 is related but the stack trace is different and this issue is not dependent on data.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

np.seterr(all="raise")

#plt.plot([1], [1])
plt.yscale("log")

Actual outcome

Traceback (most recent call last):
  File ".../.PyCharmCE2019.2/config/scratches/scratch_44.py", line 7, in <module>
    plt.yscale("log")
  File ".../venv/lib/python3.6/site-packages/matplotlib/pyplot.py", line 3088, in yscale
    return gca().set_yscale(value, **kwargs)
  File ".../venv/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 3711, in set_yscale
    self.autoscale_view(scalex=False)
  File ".../venv/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2498, in autoscale_view
    'minposy', self.yaxis, self._ymargin, y_stickies, self.set_ybound)
  File ".../venv/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2486, in handle_single_axis
    x0, x1 = inverse_trans.transform([x0t, x1t])
  File ".../venv/lib/python3.6/site-packages/matplotlib/transforms.py", line 1394, in transform
    res = self.transform_affine(self.transform_non_affine(values))
  File ".../venv/lib/python3.6/site-packages/matplotlib/scale.py", line 334, in transform_non_affine
    return ma.power(self.base, a)
  File ".../venv/lib/python3.6/site-packages/numpy/ma/core.py", line 6717, in power
    result = np.where(m, fa, umath.power(fa, fb)).view(basetype)
FloatingPointError: underflow encountered in power

Matplotlib version

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 3.1.1
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.6.8
  • Other libraries: Numpy == 1.17.2

All packages were installed using pip.

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