Articles on Trending Technologies

Technical articles with clear explanations and examples

How to make axes transparent in Matplotlib?

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

To make axes transparent in Matplotlib, you can use the set_alpha() method or patch.set_alpha() to control the transparency level. A lower alpha value creates more transparency, while higher values make the axes more opaque. Basic Axes Transparency Here's a simple example showing how to create transparent axes ? import matplotlib.pyplot as plt import numpy as np # Set figure size plt.rcParams["figure.figsize"] = [8, 6] plt.rcParams["figure.autolayout"] = True # Create figure and axes fig, ax = plt.subplots() # Create sample data x = np.linspace(0, 10, 100) y = np.sin(x) # Plot the data ...

Read More

How to name different lines in the same plot of Matplotlib?

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

To name different lines in the same plot of matplotlib, we can use the label parameter in the plot() method and display them with legend(). This helps distinguish between multiple data series on the same plot. Steps to Name Different Lines Set the figure size and adjust the padding between and around the subplots. Create data points for different lines. Plot each line using plot() method with unique label parameter. Add a legend to display the line names using legend(). Display the figure using show() method. Example Here's how to plot multiple lines with ...

Read More

Drawing circles on an image with Matplotlib and NumPy

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

Drawing circles on an image combines image processing with matplotlib's patch functionality. This technique is useful for highlighting regions of interest, marking detected objects, or creating visual annotations. Basic Circle Drawing Here's how to draw circles on a sample image using matplotlib patches ? import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import Circle # Set figure size and layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Read an image from file img = plt.imread('bird.jpg') # Generate random positions for circles x = np.random.rand(5) * img.shape[1] y = np.random.rand(5) * ...

Read More

How to change the legend fontname in Matplotlib?

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

To change the legend fontname in Matplotlib, you can use several approaches. The most common methods are using the fontname parameter in legend() or setting font properties for individual legend text elements. Method 1: Using fontname Parameter The simplest way is to specify the fontname parameter directly in the legend() method ? 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 data points x = np.linspace(-5, 5, 100) # Plot functions plt.plot(x, np.sin(x), label="y=sin(x)") plt.plot(x, np.cos(x), label="y=cos(x)") # Add legend ...

Read More

Adding units to heatmap annotation in Seaborn

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

To add units to a heatmap annotation in Seaborn, we can customize the text annotations after creating the heatmap. This is useful for displaying data with specific units like percentages, currency, or measurements. Steps to Add Units Set the figure size and adjust the padding between and around the subplots. Create a 5×5 dimension matrix using NumPy. Plot rectangular data as a color-encoded matrix. Annotate heatmap values with %age unit. To display the figure, use show() method. Example Here's how to create a heatmap and add percentage units to the annotations − ...

Read More

How to color a Matplotlib scatterplot using a continuous value?

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

To color a matplotlib scatterplot using continuous values, we can map a third variable to the color of each point. This creates a visual representation where color intensity or hue represents the magnitude of the continuous variable. Basic Scatterplot with Continuous Coloring Here's how to create a scatter plot where colors represent continuous values ? import numpy as np import matplotlib.pyplot as plt # Set figure size and layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Generate random data points x, y, z = np.random.rand(3, 50) # Create figure and subplots f, ...

Read More

Text alignment in a Matplotlib legend

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

Text alignment in a Matplotlib legend allows you to control how the legend text is positioned. You can set horizontal alignment using the set_ha() method on legend text objects. Basic Legend Text Alignment Here's how to align legend text to the left ? import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-5, 5, 100) plt.plot(x, np.sin(x), label="$y=sin(x)$") plt.plot(x, np.cos(x), label="$y=cos(x)$") legend = plt.legend(loc='upper right') for t in legend.get_texts(): t.set_ha('left') plt.show() Different Alignment Options You ...

Read More

Plot Matplotlib 3D plot_surface with contour plot projection

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

To create a 3D surface plot with contour projections in Matplotlib, we combine plot_surface() for the main surface and contourf() for projecting contours onto the coordinate planes. Understanding the Components A surface plot with contour projections consists of: A 3D surface using plot_surface() Contour projections on the XY, XZ, and YZ planes using contourf() The zdir parameter controls which plane the contour is projected onto Basic Example Here's how to create a surface plot with contour projections ? import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import ...

Read More

How to add Matplotlib Colorbar Ticks?

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

A colorbar in Matplotlib displays the color scale used in a plot. By default, Matplotlib automatically places ticks on the colorbar, but you can customize these ticks to show specific values or improve readability. Basic Colorbar with Custom Ticks Here's how to add custom ticks to a colorbar using np.linspace() ? 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 data x, y = np.mgrid[-1:1:100j, -1:1:100j] z = (x + y) * np.exp(-5.0 * (x ** 2 + y ** 2)) ...

Read More

How to change the font properties of a Matplotlib colorbar label?

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

To change the font properties of a Matplotlib colorbar label, you can customize the label using various font parameters like weight, size, and family. Here's how to modify colorbar label properties effectively. Steps to Change Colorbar Label Font Properties Set the figure size and adjust the padding between and around the subplots. Create x, y and z data points using numpy. Use imshow() method to display the data as an image, i.e., on a 2D regular raster. Create a colorbar for a ScalarMappable instance, mappable. Using colorbar axes, set the font properties such that the label is ...

Read More
Showing 4441–4450 of 61,297 articles
« Prev 1 443 444 445 446 447 6130 Next »
Advertisements