Matplotlib Articles

Page 54 of 91

Plotting distance arrows in technical drawing in Matplotlib

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

To plot distance arrows in technical drawing in Matplotlib, we can use the annotate() method with arrow properties. This is particularly useful for creating dimensional annotations in engineering drawings or technical illustrations. Basic Distance Arrow Example Here's how to create a simple distance arrow between two horizontal lines ? import matplotlib.pyplot as plt # Set figure size and layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Draw two horizontal lines plt.axhline(3.5, color='black', linewidth=2) plt.axhline(2.5, color='black', linewidth=2) # Create bidirectional arrow plt.annotate( '', xy=(0.5, 3.5), xycoords='data', ...

Read More

Setting the same axis limits for all subplots in Matplotlib

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

Setting the same axis limits for all subplots in Matplotlib ensures consistent scaling across multiple plots. You can achieve this using sharex and sharey parameters or by explicitly setting limits on each subplot. Method 1: Using sharex and sharey Parameters The most efficient approach is to share axes between subplots ? import matplotlib.pyplot as plt import numpy as np # Set figure size plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] = True # Create first subplot and set limits ax1 = plt.subplot(2, 2, 1) ax1.set_xlim(0, 5) ax1.set_ylim(0, 5) ax1.plot([1, 4, 3], 'b-o', label='Plot 1') ax1.set_title('Subplot 1') ...

Read More

Logscale plots with zero values in Matplotlib

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

Matplotlib's logarithmic scaling fails when data contains zero values because log(0) is undefined. The symlog (symmetric logarithm) scale solves this by using linear scaling near zero and logarithmic scaling for larger values. Understanding Symlog Scale The symlog scale combines linear and logarithmic scaling. It uses linear scaling within a threshold around zero and logarithmic scaling beyond that threshold, making it perfect for data containing zero values. Basic Example with Zero Values Here's how to create a symlog plot with data containing zeros − import matplotlib.pyplot as plt # Data with zero values x ...

Read More

Adjusting Text background transparency in Matplotlib

Farhan Muhamed
Farhan Muhamed
Updated on 25-Mar-2026 4K+ Views

The matplotlib library in Python allows us to create graphs and plots for data visualization. This library has several built-in functions to style plots, such as changing colors, adding titles, setting backgrounds, labels, and adjusting layouts. In this article, we will learn how to adjust the transparency of text backgrounds in matplotlib plots. Text Backgrounds in Matplotlib In matplotlib, text backgrounds refer to the area behind text elements such as titles, labels, and annotations in a plot. By default, the background of text is transparent, but we can change it to a solid color or a semi-transparent color ...

Read More

How to plot a dashed line on a Seaborn lineplot in Matplotlib?

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

To plot a dashed line on a Seaborn lineplot, we can use linestyle="dashed" in the argument of lineplot(). This creates visually distinct line patterns that are useful for differentiating multiple data series. Steps Set the figure size and adjust the padding between and around the subplots. Create x and y data points using numpy. Use lineplot() method with x and y data points in the argument and linestyle="dashed". To display the figure, use show() method. Example import seaborn as sns import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = ...

Read More

How to skip empty dates (weekends) in a financial Matplotlib Python graph?

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

When creating financial charts in Matplotlib, you often need to skip weekends (Saturday and Sunday) to display only business days. This prevents gaps in your time series visualization and provides a cleaner representation of trading data. Understanding Weekdays in Python Python's weekday() method returns integers where Monday=0, Tuesday=1, ..., Saturday=5, Sunday=6. To skip weekends, we check if weekday() returns 5 (Saturday) or 6 (Sunday). Basic Example Here's how to plot only weekdays while skipping weekends ? import pandas as pd import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] ...

Read More

How to write annotation outside the drawing in data coords in Matplotlib?

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

In Matplotlib, you can place annotations outside the plotting area using the annotate() method with specific coordinate systems. This is useful for adding titles, labels, or explanatory text that shouldn't interfere with your data visualization. Understanding Coordinate Systems Matplotlib offers different coordinate systems for positioning annotations ? Data coordinates: Based on your actual data values Axes coordinates: Relative to the axes (0-1 range) Transform coordinates: Using axis transforms for positioning outside plot area Basic Example with Transform Coordinates Here's how to place an annotation ...

Read More

Histogram for discrete values with Matplotlib

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

To plot a histogram for discrete values with Matplotlib, we can use the hist() method. Discrete histograms are useful for visualizing the frequency distribution of categorical or integer data points. Steps Set the figure size and adjust the padding between and around the subplots. Create a list of discrete values. Use hist() method to plot data with bins=length of data and edgecolor='black'. To display the figure, use show() method. Example Let's create a histogram for discrete values with proper bin configuration ? ...

Read More

Plotting only the upper/lower triangle of a heatmap in Matplotlib

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

To plot only the upper or lower triangle of a heatmap in Matplotlib, we can use NumPy to create a mask that hides specific parts of the data. This technique is useful for correlation matrices where the upper and lower triangles contain identical information. Plotting Lower Triangle Heatmap We use numpy.tri() to create a triangular mask and apply it to our data − 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 random 5x5 data data = np.random.rand(5, 5) # Create ...

Read More

Is it possible to control Matplotlib marker orientation?

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

To control matplotlib marker orientation, we can use marker tuples that contain the number of sides, style, and rotation angle of the marker. This technique is particularly useful for creating custom arrow-like markers or rotating polygonal shapes. Understanding Marker Tuples A marker tuple follows the format (numsides, style, angle) where − numsides − Number of sides for the polygon marker style − Style of the marker (0 for regular polygon) angle − Rotation angle in degrees Basic Example with Fixed Rotation Let's start with a simple example showing triangular markers with different orientations ...

Read More
Showing 531–540 of 902 articles
« Prev 1 52 53 54 55 56 91 Next »
Advertisements