Articles on Trending Technologies

Technical articles with clear explanations and examples

How to pixelate a square image to 256 big pixels with Python Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 405 Views

To pixelate a square image to 256 big pixels with Python, we can use PIL (Python Imaging Library) to resize the image in two steps: first shrink it to create the pixelated effect, then scale it back up. This technique creates the classic "big pixel" or mosaic appearance. Understanding the Process The pixelation process works by: Resizing the original image to a very small size (16x16 = 256 pixels) Using bilinear resampling to reduce detail and create pixel blocks Scaling back up to the original size using nearest neighbor to preserve the pixelated look ...

Read More

How to animate a Seaborn heatmap or correlation matrix(Matplotlib)?

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

To animate a Seaborn heatmap or correlation matrix, we can use matplotlib's FuncAnimation class to create dynamic visualizations. This technique is useful for showing how data changes over time or displaying random data patterns. Basic Setup First, let's set up the required imports and figure configuration ? import numpy as np import seaborn as sns import matplotlib.pyplot as plt from matplotlib import animation # Set figure size and layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True Creating an Animated Heatmap Here's how to create an animated heatmap with randomly changing data ? ...

Read More

How to turn off transparency in Matplotlib's 3D Scatter plot?

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

In Matplotlib's 3D scatter plot, transparency effects can make data points appear faded or overlapped. To create solid, non-transparent scatter points, you need to control the alpha and depthshade parameters. Key Parameters Two main parameters control transparency in 3D scatter plots: alpha − Controls overall transparency (0=transparent, 1=opaque) depthshade − When False, prevents automatic depth-based shading Example Here's how to create a 3D scatter plot with no transparency effects ? import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Set figure size plt.rcParams["figure.figsize"] = [8, 6] ...

Read More

How to plot the outline of the outer edges on a Matplotlib line in Python?

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

To plot the outline of the outer edges on a Matplotlib line in Python, we can create a visual effect by layering two lines with different widths and colors. This technique creates an outlined appearance by drawing a thicker background line followed by a thinner foreground line. Basic Outline Effect The key is to plot the same line twice − first with a thicker line width for the outline, then with a thinner line width for the main line ? import numpy as np import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.50, ...

Read More

How to merge two existing Matplotlib plots into one plot?

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

Matplotlib allows you to combine data from multiple plots into a single visualization. This is useful when you want to merge separate plot lines or analyze combined datasets. Basic Plot Merging Example Here's how to extract data from existing plots and combine them into one ? import numpy as np import matplotlib.pyplot as plt # Configure figure settings plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] = True # Create sample data x = np.linspace(-10, 10, 100) y1 = np.sin(x) y2 = np.cos(x) # Create first subplot with two separate plots plt.subplot(211) plt.plot(x, y1, color='red', linewidth=2, ...

Read More

How does imshow handle the alpha channel with an M x N x 4 input?(Matplotlib)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 463 Views

Matplotlib's imshow() function can handle RGBA images using M×N×4 arrays, where the fourth channel represents the alpha (transparency) values. Let's explore how to create and display images with transparency effects. Understanding RGBA Format An M×N×4 array represents an RGBA image where: Red channel − d[:, :, 0] Green channel − d[:, :, 1] Blue channel − d[:, :, 2] Alpha channel − d[:, :, 3] (0=transparent, 255=opaque) Basic RGBA Image Example Let's create a simple RGBA image with varying transparency − import numpy as np import matplotlib.pyplot as plt # ...

Read More

How to set a Matplotlib rectangle edge to outside of specified width?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 632 Views

To set a Matplotlib rectangle edge to outside of a specified width, you need to use AnnotationBbox with AuxTransformBox. This technique allows you to create a rectangle with an outer border that extends beyond the rectangle's actual boundaries. Basic Rectangle with Outer Edge Here's how to create a rectangle with an edge extending outside its specified width ? import matplotlib.pyplot as plt from matplotlib.patches import Rectangle from matplotlib.offsetbox import AnnotationBbox, AuxTransformBox # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure and subplot fig = plt.figure() ax = fig.add_subplot(111) ax.plot([1, ...

Read More

How to add a cursor to a curve in Matplotlib?

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

Adding a cursor to a curve in Matplotlib allows users to interactively explore data points by hovering over the plot. This is achieved by creating a custom cursor class that responds to mouse events and updates visual elements in real-time. Creating the Cursor Class First, we need to create a cursor class that handles the visual elements and mouse interactions ? import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True class CursorClass(object): def __init__(self, ax, x, y): ...

Read More

Creating animated GIF files out of D3.js animations in Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 501 Views

To create animated GIF files from matplotlib animations, we can use the PillowWriter class. This technique is useful for creating animated visualizations that can be easily shared on web platforms or embedded in presentations. Steps to Create Animated GIFs Set up the matplotlib figure and axes Create initial plot elements (lines, points, etc.) Define initialization and animation functions Create a FuncAnimation object Use PillowWriter to save as GIF format Example: Animated Sine Wave Here's how to create an animated sine wave and save it as a GIF ? import numpy as np ...

Read More

How to convert Matplotlib figure to PIL Image object?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 11K+ Views

Converting a Matplotlib figure to a PIL Image object allows you to manipulate the plot using PIL's image processing capabilities. This is useful when you need to apply filters, transformations, or integrate the plot into image processing workflows. Step-by-Step Process To convert a Matplotlib figure to PIL Image object, follow these steps − Set the figure size and adjust the padding between and around the subplots Create a new figure or activate an existing figure Plot your data using plot() method Initialize an in-memory buffer using io.BytesIO() Save the figure to the buffer in PNG format ...

Read More
Showing 4101–4110 of 61,297 articles
« Prev 1 409 410 411 412 413 6130 Next »
Advertisements