How does Python's Matplotlib.pyplot.quiver exactly work?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 22:03:31

328 Views

Matplotlib's pyplot.quiver() creates 2D field plots by drawing arrows to represent vectors at specific coordinates. Each arrow shows both direction and magnitude of vector data. Syntax plt.quiver(X, Y, U, V, **kwargs) Parameters X, Y − Arrow positions (starting points) U, V − Arrow directions and magnitudes (vector components) angles − How to interpret U and V ('xy' uses coordinate system) scale_units, scale − Controls arrow sizing color − Arrow colors (single color or array) Basic Example Let's create a simple quiver plot with three vectors ? import numpy ... Read More

How to repress scientific notation in factorplot Y-axis in Seaborn / Matplotlib?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 22:03:07

6K+ Views

When working with large numbers in Seaborn plots, the Y-axis often displays values in scientific notation (e.g., 1e6). To suppress this and show plain numbers, we can use the ticklabel_format() method with style="plain". Understanding the Problem Seaborn's catplot() (formerly factorplot()) uses Matplotlib's automatic formatting, which switches to scientific notation for large numbers. This can make plots harder to read in many contexts. Solution Using ticklabel_format() The plt.ticklabel_format() method controls how tick labels are displayed. Setting style="plain" forces regular decimal notation instead of scientific notation. Example import matplotlib.pyplot as plt import pandas as pd ... Read More

How to make axes transparent in Matplotlib?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 22:02:46

4K+ 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
Updated on 25-Mar-2026 22:02:22

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
Updated on 25-Mar-2026 22:01:55

3K+ 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
Updated on 25-Mar-2026 22:01:33

874 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
Updated on 25-Mar-2026 22:01:14

726 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
Updated on 25-Mar-2026 22:00:58

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
Updated on 25-Mar-2026 22:00:37

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
Updated on 25-Mar-2026 22:00:20

840 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

Advertisements