Here are the matplotlib.pyplot.pcolormesh() in Python – coding

Matplotlib is a library in Python and it’s numerical – mathematical extension  NumPy library. Pyplot is state-based interface to  Matplotlib module that supplies a MATLAB-like interface.

The pcolormesh() perform in pyplot module of matplotlib library is used to create a pseudocolor plot  a non-regular rectangular grid.

Syntax:

matplotlib.pyplot.pcolormesh(*args, alpha=None, norm=None, cmap=None, vmin=None, vmax=None, shading='flat', antialiased=False, data=None, **kwargs)

Parameters: This technique settle for the next parameters which are described under:

  • C : This parameter comprises the values in 2D array that are to be color-mapped.
  • X, Y: These parameter are the coordinates of the quadrilateral corners.
  • cmap : This parameter is a colormap occasion or registered colormap title.
  • norm : This parameter is the Normalize occasion scales the data values to the canonical colormap range [0, 1] for mapping to colours
  • vmin, vmax : These parameter are optionally available in nature and they’re colorbar range.
  • alpha : This parameter is a depth of the colour.
  • snap : This parameter is used to snap the mesh to pixel boundaries.
  • edgecolors : This parameter is the colour of the sides. ‘none’, None, ‘face’, colour, colour sequence
  • shading : This parameter is the fill model. It cabe flat or gouraud.

Returns: This returns the next:

  • mesh : This returns the matplotlib.collections.QuadMesh

Below examples illustrate the matplotlib.pyplot.pcolormesh() perform in matplotlib.pyplot:

Example #1:

import matplotlib.pyplot as plt

import numpy as np

from matplotlib.colours import LogNorm

    

Z = np.random.rand(25, 25)

    

plt.pcolormesh(Z)

 

plt.title('matplotlib.pyplot.pcolormesh() perform Example', fontweight ="bold")

plt.present()

Output:

Example #2:

import matplotlib.pyplot as plt

import numpy as np

from matplotlib.colours import LogNorm

    

dx, dy = 0.015, 0.05

y, x = np.mgrid[slice(-4, 4 + dy, dy),

                slice(-4, 4 + dx, dx)]

z = (1 - x / 3. + x ** 6 + y ** 3) * np.exp(-x ** 2 - y ** 2)

z = z[:-1, :-1]

z_min, z_max = -np.abs(z).max(), np.abs(z).max()

    

c = plt.pcolormesh(x, y, z, cmap ='Greens', vmin = z_min, vmax = z_max)

plt.colorbar(c)

 

plt.title('matplotlib.pyplot.pcolormesh() perform Example', fontweight ="bold")

plt.present()

Output:

Add a Comment

Your email address will not be published.