Matplotlib.pyplot.pcolor() function in Python
Last Updated : 25 Nov, 2020
Matplotlib is the well-known Python package used in data visualization. Numpy is the numerical mathematics extension of Matplotlib. Matplotlib is capable of producing high-quality graphs, charts, and figures. Matplotlib produces object-oriented API for embedding plots into projects using GUI toolkits like Tkinter, wxPython, or Qt. John D. Hunter was the original developer of Matplotlib and it is distributed under a BSD-style license.
matplotlib.pyplot.pcolor()
Matplotlib contains a wide range of functions that help in performing different tasks, one of them is matplotlib.pyplot.pcolor() function. The pcolor() function in the pyplot module of the Matplotlib library helps to create a pseudo-color plot with a non-regular rectangular grid.
Syntax: matplotlib.pyplot.pcolor(*args, alpha=None, norm=None, cmap=None, vmin=None, vmax=None, data=None, **kwargs) Call Signature: pcolor([X, Y,] C, **kwargs) Parameters: C: Denotes a scaler 2-D array X, Y: array_like, optional, coordinates of quadrilateral corners cmap: str or Colormap, optional norm: Normalize, optional vmin, vmax: scaler, optional edgecolors: {'none', None, 'face', color sequence}, optional alpha: scaler, optional snap: bool, optional Other Parameters: antialiaseds: bool, optional **kwargs Returns: The function returns a collection i.e matplotlib.collections.Collection
Note: In case of larger arrays, matplotlib.pyplot.pcolor() works very slow.
Below examples demonstrate the working of matplotlib.pyplot.pcolor() function:
Example 1: Generating images using pcolor() function
With the help of pcolor() function, we can generate 2-D image-style plots, as shown below
Python3 # Demonstration of matplotlib function import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import LogNorm Z = np.random.rand(4, 12) fig, (ax0, ax1) = plt.subplots(2, 1) c = ax0.pcolor(Z) ax0.set_title('No edge image') c = ax1.pcolor(Z, edgecolors='k', linewidths=5) ax1.set_title('Thick edges image') fig.tight_layout() plt.show()
Output:
Example 2: Working of pcolor() with Log scale
Python3 # Demonstration of matplotlib function import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import LogNorm N = 100 X, Y = np.mgrid[-4:4:complex(0, N), -4:4:complex(0, N)] # Image show that a low hump with a spike coming out. # We need a z/colour axis on a log scale in order # to watch both hump and spike. Z1 = np.exp(-(X)**2 - (Y)**2) Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2) Z = Z1 + 50 * Z2 fig, (ax0, ax1) = plt.subplots(2, 1) c = ax0.pcolor(X, Y, Z,norm=LogNorm(vmin=Z.min(), vmax=Z.max()), cmap=plt.cm.autumn) fig.colorbar(c, ax=ax0) c = ax1.pcolor(X, Y, Z, cmap=plt.cm.autumn) fig.colorbar(c, ax=ax1) plt.show()
Output:
Similar Reads
Matplotlib.pyplot.plot() function in Python The matplotlib.pyplot.plot() is used to create 2D plots such as line graphs and scatter plots. The plot() function allows us to plot data points, customize line styles, markers and colors making it useful for various types of visualizations. In this article, we'll see how to use this function to plo
3 min read
Matplotlib.pyplot.setp() function in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot,
2 min read
Matplotlib.pyplot.fill() function in Python Matplotlib.pyplot.fill() function is used to fill the area enclosed by polygon /curve. Syntax: matplotlib.pyplot.fill(*args, data=None, **kwargs) Parameters: *args: sequence of x, y, [color] Â Â Â sequence of x,y = To traverse the boundaries of the polygon or curve defined by lists of x and y positi
2 min read
matplotlib.pyplot.pcolormesh() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.pcolormesh() Function: The pcolormesh() function in pyplot module of matplotlib library
2 min read
Matplotlib.pyplot.hexbin() function in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot,
2 min read