8000 [Bug]: Saving a fig with a colorbar using a `TwoSlopeNorm` sometimes results in 'posx and posy should be finite values' · Issue #22300 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[Bug]: Saving a fig with a colorbar using a TwoSlopeNorm sometimes results in 'posx and posy should be finite values' #22300

@cgadal

Description

@cgadal

Bug summary

When saving a figure with a colorbar and a mappable using a TwoSlopeNorm, it sometimes results in posx and posy should be finite values. The saved figure then lacks of a label for the colorbar.

Note that:

  • you need to specify a vmax smaller than or equat to 0.9989999999999999
  • this looks independent of the max and min values of Z. Tested with Z = 10000*(X**3 - Y**4) and Z = (X**3 - Y**4)/10000

it dos not happen:

  • if the figure is not saved but only shown
  • with previous versions of matplotlib

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as colors

x = np.linspace(0, 1, 100)
y = x.copy()
X, Y = np.meshgrid(x, y)
Z = X**3 - Y**4


divnorm = colors.TwoSlopeNorm(vcenter=0, vmax=0.1)

fig = plt.figure()
c = plt.pcolormesh(x, y, Z, cmap='seismic', norm=divnorm)
plt.colorbar(c, label='Velocity [cm/s]')
plt.savefig('Spatio_temporal_velocity.png')
plt.show()

Actual outcome

divnorm

Expected outcome

It should display the colorbar label, and not return in the terminal posx and posy should be finite values.

Additional information

  • you need to specify a vmax smaller than or equat to 0.9989999999999999
  • this looks independent of the max and min values of Z. Tested with Z = 10000*(X**3 - Y**4) and Z = (X**3 - Y**4)/10000

it dos not happen:

  • if the figure is not saved but only shown
  • with previous versions of matplotlib

Operating system

Ubuntu 20

Matplotlib Version

3.5.0

Matplotlib Backend

QtAgg

Python version

3.8.10

Jupyter version

No response

Installation

pip

Metadata

Metadata

461A

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0