Articles on Trending Technologies

Technical articles with clear explanations and examples

Set a colormap of an image in Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 3K+ Views

A colormap in Matplotlib defines how numerical data values are mapped to colors when displaying images. You can apply different colormaps to visualize image data in various color schemes. Basic Colormap Usage Here's how to apply a colormap to an image using matplotlib ? import matplotlib.pyplot as plt import numpy as np # Create sample image data data = np.random.random((100, 100)) plt.figure(figsize=(8, 6)) plt.imshow(data, cmap='hot') plt.colorbar() plt.title('Hot Colormap') plt.axis('off') plt.show() Working with Real Image Data When working with RGB images, you typically need to extract a single channel before applying a ...

Read More

Plotting at full resolution with matplotlib.pyplot, imshow() and savefig()

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 5K+ Views

To plot at full resolution with matplotlib.pyplot, imshow() and savefig(), we can set the DPI (dots per inch) value between 600 to 1200 for high-quality output. This is essential when creating publication-ready images or detailed visualizations. Key Parameters for High Resolution The main parameters that control image quality are: dpi − Dots per inch, controls resolution (600-1200 for high quality) bbox_inches='tight' − Removes extra whitespace pad_inches − Controls padding around the figure Basic High-Resolution Example Here's how to create and save a high-resolution image using imshow() ? import matplotlib.pyplot as plt ...

Read More

How to apply pseudo color schemes to an image plot in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 679 Views

Pseudocolor schemes can enhance contrast and make data visualization more effective, especially when presenting on projectors with poor contrast. Pseudocolor is particularly useful for single-channel grayscale images where different color maps can highlight various data patterns. Pseudocolor is only relevant to single-channel, grayscale, luminosity images. Since R, G, and B channels are often similar in many images, we can extract one channel and apply different color schemes to visualize the data more effectively. Basic Pseudocolor Application Here's how to apply a pseudocolor scheme to an image using matplotlib ? import matplotlib.pyplot as plt import matplotlib.image ...

Read More

3D scatterplots in Python Matplotlib with hue colormap and legend

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 3K+ Views

3D scatter plots with hue colormaps allow you to visualize four dimensions of data simultaneously: x, y, z coordinates and a color dimension. In this tutorial, we'll create 3D scatter plots using Matplotlib with Seaborn color palettes and legends. Basic 3D Scatter Plot with Hue Colormap Let's create a 3D scatter plot where points are colored based on their x-coordinate values ? import numpy as np import seaborn as sns from matplotlib import pyplot as plt from matplotlib.colors import ListedColormap # Set figure size plt.rcParams["figure.figsize"] = [8.00, 6.00] plt.rcParams["figure.autolayout"] = True # Generate random ...

Read More

How do I fix the deprecation warning that comes with pylab.pause?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 257 Views

The pylab.pause() function has been deprecated in recent versions of matplotlib. This article shows how to suppress the deprecation warning and provides modern alternatives. Suppressing the Deprecation Warning You can suppress the warning using warnings.filterwarnings("ignore") before calling the deprecated function − import matplotlib.pyplot as plt import matplotlib.pylab as pl import warnings plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True warnings.filterwarnings("ignore") pl.pause(0) plt.show() Modern Alternative: Using plt.pause() Instead of using the deprecated pylab.pause(), use plt.pause() directly − import matplotlib.pyplot as plt import numpy as np # Create a simple ...

Read More

How to place customized legend symbols on a plot using Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 1K+ Views

Matplotlib allows you to create customized legend symbols by inheriting from legend handler classes. This is useful when you want legend symbols that differ from the actual plot elements or need special shapes like ellipses. Creating Custom Legend Handler First, we create a custom handler class that inherits from HandlerPatch to define how our legend symbol should appear ? import matplotlib.pyplot as plt import matplotlib.patches as mpatches from matplotlib.legend_handler import HandlerPatch class HandlerEllipse(HandlerPatch): def create_artists(self, legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans): ...

Read More

How to plot a single line in Matplotlib that continuously changes color?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 2K+ Views

To plot a single line that continuously changes color in Matplotlib, you can segment the line into small parts and assign different colors to each segment. This creates a smooth color transition effect along the line. Steps Here's how to create a color-changing line ? Set the figure size and adjust the padding between subplots Create data points using NumPy (we'll use a sine wave) Create a figure and subplot Iterate through the data in small segments Plot each segment with a different random color Display the figure using show() method Example ...

Read More

Setting the Matplotlib title in bold while using "Times New Roman

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 10K+ Views

To set the Matplotlib title in bold while using "Times New Roman", we can use fontweight="bold" along with fontname="Times New Roman" in the set_title() method. Basic Example Here's how to create a scatter plot with a bold Times New Roman title − import numpy as np import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure and subplot fig, ax = plt.subplots() # Generate random data points x = np.random.rand(100) y = np.random.rand(100) # Create scatter plot ax.scatter(x, y, c=y, marker="v") # Set ...

Read More

Plot a 3D surface from {x,y,z}-scatter data in Python Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 5K+ Views

To plot a 3D surface from x, y and z scatter data in Python, we can use matplotlib's plot_surface() method. This creates stunning 3D visualizations from coordinate data. Basic 3D Surface Plot Here's how to create a 3D surface plot using mathematical function data ? import matplotlib.pyplot as plt import numpy as np # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure and 3D axes fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Generate coordinate data x = np.linspace(-2, 2, 100) y = np.linspace(-2, 2, 10) X, Y ...

Read More

How can I get the (x,y) values of a line that is plotted by a contour plot (Matplotlib)?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 498 Views

To get the (x, y) values of a line plotted by a contour plot in Matplotlib, you need to access the contour collections and extract the path vertices. This is useful for analyzing specific contour lines or extracting data for further processing. Steps to Extract Contour Line Coordinates Create a contour plot using contour() method Access the contour collections from the returned object Get the paths from each collection Extract vertices (x, y coordinates) from each path Example Here's how to extract the (x, y) coordinates from contour lines ? import matplotlib.pyplot ...

Read More
Showing 1–10 of 61,303 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements