Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

How to plot a 3D patch collection in matplotlib?

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

To plot a 3D patch collection in matplotlib, we can create patches (like circles) and position them on different 3D planes. The pathpatch_2d_to_3d() method converts 2D patches into 3D objects that can be displayed in a 3D plot. Steps to Create a 3D Patch Collection Set the figure size and adjust the padding between and around the subplots. Create a new figure or activate an existing figure. Get the current axes and set projection as 3d. Iterate through coordinate directions and create circle patches using pathpatch_2d_to_3d() method to convert a PathPatch to a PathPatch3D object. To display ...

Read More

How to fill the area under a curve in a Seaborn distribution plot?

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

To fill the area under a curve in a Seaborn distribution plot, we can use displot() with the fill parameter or combine histplot() with matplotlib's fill_between() method for custom styling. Method 1: Using displot() with fill Parameter The simplest approach is to use Seaborn's built-in fill parameter ? import seaborn as sns import matplotlib.pyplot as plt import numpy as np # Generate sample data np.random.seed(42) data = np.random.normal(50, 15, 1000) # Create distribution plot with filled area plt.figure(figsize=(8, 5)) sns.displot(data, kind="kde", fill=True, color="skyblue", alpha=0.7) plt.title("Distribution Plot with Filled Area") plt.show() Method 2: ...

Read More

How to adjust 'tick frequency' in Matplotlib for string X-axis?

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

To adjust tick frequency for string X-axis in Matplotlib, you need to control which string labels appear on the axis. This is useful when you have many categorical labels that would overlap or clutter the display. Basic Tick Frequency Adjustment Here's how to adjust tick frequency when working with string labels on the X-axis ? import matplotlib.pyplot as plt import numpy as np # Sample string labels for X-axis months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] sales ...

Read More

Saving scatterplot animations with matplotlib

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

To save scatterplot animations with matplotlib, we need to create an animation loop that generates multiple frames and exports them as a video file or GIF. This technique is useful for visualizing data that changes over time or showing algorithmic processes. Basic Setup First, let's set up the required imports and create sample data for our animation ? import matplotlib.pyplot as plt import matplotlib.animation as animation import numpy as np # Set figure size and layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Animation parameters steps = 50 nodes = 100 positions = ...

Read More

How to plot a line (polygonal chain) with matplotlib with minimal smoothing?

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

To plot a line (polygonal chain) with matplotlib with minimal smoothing, you can use scipy's interpolation methods. The pchip() function provides monotonic cubic interpolation that preserves the shape of your data while adding smooth curves between points. Steps to Create a Smooth Line Plot Set the figure size and adjust the padding between and around the subplots Initialize a variable N to get the number of data points Create x and y data points using numpy Get 1-D monotonic cubic interpolation using pchip() method Plot the interpolated line and original data points Display the figure using show() ...

Read More

Check if points are inside ellipse faster than contains_point method (Matplotlib)

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

When checking if multiple points are inside an ellipse, the mathematical approach is significantly faster than using Matplotlib's contains_point() method. This technique uses the ellipse equation with coordinate transformation to handle rotated ellipses efficiently. Mathematical Approach for Point-in-Ellipse Testing The key is to transform coordinates and apply the ellipse equation directly rather than using the slower contains_point() method ? import matplotlib.pyplot as plt import matplotlib.patches as patches import numpy as np # Set up the figure plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots(1) ax.set_aspect('equal') # Generate random test points ...

Read More

Changing the color of a single X-axis tick label in Matplotlib

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

To change the color of a single X-axis tick label in matplotlib, you can use the tick_params() method to change all tick labels, or target specific labels using get_xticklabels() for individual customization. Method 1: Changing All X-axis Tick Labels Use tick_params() to change the color of all X-axis tick labels at once − 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 figure and subplot fig = plt.figure() ax = fig.add_subplot(111) # Create data x = np.linspace(-10, 10, 100) y = ...

Read More

How to appropriately plot the losses values acquired by (loss_curve_) from MLPClassifier? (Matplotlib)

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

The MLPClassifier from scikit-learn provides a loss_curve_ attribute that tracks training loss at each iteration. Plotting these values helps visualize training convergence across different hyperparameters and datasets. Understanding MLPClassifier Loss Curves The loss_curve_ attribute stores the loss function value after each iteration during training. By plotting these values, we can compare how different solvers and learning rates affect convergence behavior. Complete Example Here's how to plot loss curves for different MLPClassifier configurations across multiple datasets ‒ import warnings import matplotlib.pyplot as plt from sklearn.neural_network import MLPClassifier from sklearn.preprocessing import MinMaxScaler from sklearn import datasets ...

Read More

How to use Font Awesome symbol as marker in matplotlib?

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

Font Awesome symbols can be used as custom markers in matplotlib plots by using Unicode characters with the text() function. This approach allows you to create visually appealing plots with unique symbolic markers. Setup and Prerequisites First, configure the figure settings and import required libraries ? import numpy as np import matplotlib.pyplot as plt # Set figure size and enable automatic layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True Using Unicode Symbols as Markers Define a list of Unicode symbols and plot them using the text() function ? import numpy ...

Read More

How to save a Librosa spectrogram plot as a specific sized image?

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

Librosa is a Python package that helps to analyze audio and music files. This package also helps to create music information retrieval systems. In this article, we will see how to save a Librosa spectrogram plot as an image of specific size. Understanding Spectrogram Parameters Before creating the spectrogram, we need to understand the key parameters that control the output image dimensions ? hl (hop_length) − Number of samples per time-step in spectrogram hi (height) − Height of the output image (number of mel bins) wi (width) − Width of the output image (time frames) ...

Read More
Showing 4121–4130 of 61,298 articles
« Prev 1 411 412 413 414 415 6130 Next »
Advertisements