Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Matplotlib pcolormesh() atributes

If I have an existing pcolormesh() object is it possible to change the vmin, vmax values? In other words, are vmin and vmax attributes of the pcolormesh object?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To see an object’s attributes you can use the dir function.

p = plt.pcolormesh(...)
print(dir(p))  # lists all the attributes for this object

You’ll see it has the .set_clim() attribute which you can use.

import numpy as np
import matplotlib.pyplot as plt

plt.close("all")

x = np.linspace(0, 1)
y = np.linspace(0, 1)
Z = x[:,None]**2 + y[None, :]**2

fig, ax = plt.subplots()
p = ax.pcolormesh(x, y, Z)
fig.colorbar(p, ax=ax)
fig.show()

fig, ax = plt.subplots()
p = ax.pcolormesh(x, y, Z)
p.set_clim(vmin=0.5, vmax=1.)
fig.colorbar(p, ax=ax)
fig.show()

First figure:

Second figure:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading