Articles on Trending Technologies

Technical articles with clear explanations and examples

Can I give a border to a line in Matplotlib plot function?

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

To give a border to a line in Matplotlib plot function, you can call plot() twice with different line widths. The first plot creates a wider border line, and the second plot creates a narrower main line on top. Basic Approach The technique involves plotting the same data twice ? First plot with wider line width for the border Second plot with narrower line width for the main line The wider line shows through as a border around the narrower line Example Here's how to create a red line with a black border ...

Read More

How to plot an emoji as a label for a bar in Matplotlib?

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

We can use Matplotlib's annotate() method to place emojis as labels on top of bars. This creates visually appealing charts that combine data visualization with expressive emoji symbols. Steps Set the figure size and adjust the padding between and around the subplots Create lists of frequencies and labels containing emojis Create a new figure using figure() method Plot bars using bar() method Use annotate() method to place emojis as labels above each bar Display the figure using show() method ...

Read More

Plot scatter points on a 3D projection with varying marker size in Matplotlib

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

To plot scatter points on a 3D projection with varying marker size in Matplotlib, we need to create 3D coordinates and define marker sizes based on data values. This creates visually appealing scatter plots where point size represents an additional dimension of data. Steps to Create 3D Scatter Plot with Varying Marker Size Set the figure size and adjust the padding between and around the subplots Create xs, ys and zs data points using NumPy Initialize a variable 's' for varying size of markers Create a figure using figure() method Add a 3D subplot using add_subplot() with ...

Read More

How to create a legend for a 3D bar in Matplotlib?

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

Creating a legend for a 3D bar chart in Matplotlib requires plotting the bars and using Rectangle patches as legend handles since 3D bars don't automatically generate legend entries. Steps to Create 3D Bar Legend Set up the figure and 3D subplot Create data arrays for bar positions and dimensions Plot 3D bars using bar3d() method Create Rectangle patches matching bar colors Use legend() method with custom handles and labels Display the figure Example import numpy as np import matplotlib.pyplot as plt # Set up the figure fig = plt.figure(figsize=(10, 6)) ax ...

Read More

Plot scatter points on 3d plot without axes and grids in Matplotlib

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

To plot scatter points on a 3D plot without axes and grids in Matplotlib, we can use the scatter() method and turn off the axes using axis('off'). This creates a clean 3D visualization focused entirely on the data points. Steps Set the figure size and adjust the padding between and around the subplots Create a new figure using figure() method Add a 3D subplot using add_subplot(projection="3d") Generate x, y, and z data points using NumPy Use scatter() method to create the 3D scatter plot Use ax.axis('off') to hide axes and grids Display the figure using show() method ...

Read More

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
Showing 1–10 of 61,303 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements