Matplotlib Articles

Page 15 of 91

How to make a rug plot in Matplotlib?

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

A rug plot is a one-dimensional visualization that displays data points as marks along an axis, making it easy to see the distribution and density of values. In Matplotlib, rug plots are often combined with density curves to provide a comprehensive view of data distribution. Basic Rug Plot Let's start with a simple rug plot using sample data points ? import numpy as np import matplotlib.pyplot as plt # Sample data points data = np.array([-6, -4, 2, 1, 4], dtype=np.float) # Create figure and axis fig, ax = plt.subplots(figsize=(8, 4)) # Create rug ...

Read More

How to fill rainbow color under a curve in Python Matplotlib?

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

Creating a rainbow gradient effect under a curve in Matplotlib involves using the fill_between() function with multiple color layers. This technique creates visually appealing plots by stacking colored regions with slightly different y-offsets. Basic Rainbow Fill Implementation The key is to plot multiple fill_between() layers, each with a different color and y-offset ? import numpy as np import matplotlib.pyplot as plt def plot_rainbow_under_curve(): rainbow_colors = ['violet', 'indigo', 'blue', 'green', 'yellow', 'orange', 'red'] x = np.linspace(-5, 5, 100) y = x ** 2 ...

Read More

How to draw axis lines inside a plot in Matplotlib?

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

In Matplotlib, you can draw axis lines inside a plot by positioning the spines at zero and hiding unnecessary borders. This creates a coordinate system where the x and y axes pass through the origin. Understanding Spines Spines are the lines connecting the axis tick marks that form the boundaries of the data area. By default, Matplotlib shows all four spines (top, bottom, left, right) around the plot area. Drawing Axis Lines Inside the Plot Here's how to position the axis lines at the center of the plot ? import numpy as np import ...

Read More

How to set same scale for subplots in Python using Matplotlib?

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

When creating subplots in Matplotlib, you often want them to share the same scale for better comparison. This is achieved using the sharex and sharey parameters when creating subplot arrangements. Using sharex Parameter The sharex parameter links the x-axis scale across subplots. When you zoom or pan one subplot, all linked subplots will follow ? import matplotlib.pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure fig = plt.figure() # Add subplots with shared x-axis ax1 = fig.add_subplot(2, 1, 1) ax2 ...

Read More

Conditional removal of labels in Matplotlib pie chart

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

To remove labels from a Matplotlib pie chart based on a condition, you can use a lambda function in the autopct parameter. This technique is useful when you want to display percentage labels only for slices that meet certain criteria, such as being above a specific threshold. Steps to Conditionally Remove Labels Set the figure size and adjust the padding between and around the subplots Create a Pandas DataFrame with your data Plot a pie chart using pie() method with conditional removal of labels Use a lambda function in autopct to show labels only when conditions are ...

Read More

Matplotlib – Make a Frequency histogram from a list with tuple elements in Python

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

To make a frequency histogram from a list with tuple elements in Python, we can extract the categories and frequencies from tuples and create a bar chart using Matplotlib. Steps to Create a Frequency Histogram Set the figure size and adjust the padding between and around the subplots Create a list of tuples containing category-frequency pairs Extract categories and frequencies by iterating through the data Create a bar plot using bar() method Display the figure using show() method Example Here's how to create a frequency histogram from tuple data ? import matplotlib.pyplot ...

Read More

How to rotate a simple matplotlib Axes?

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

To rotate a simple matplotlib axes, we can use the Affine2D transformation along with floating_axes. This technique creates a rotated coordinate system for plotting data at different angles. Required Imports First, import the necessary packages for creating rotated axes ? import matplotlib.pyplot as plt from matplotlib.transforms import Affine2D import mpl_toolkits.axisartist.floating_axes as floating_axes Steps to Rotate Axes The rotation process involves these key steps: Create an affine transformation − Define the rotation angle using Affine2D().rotate_deg() Set axis limits − Define the coordinate range for both x and y axes Create grid helper ...

Read More

How to add a 3d subplot to a matplotlib figure?

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

To add a 3D subplot to a matplotlib figure, you need to specify projection='3d' when creating the subplot. This enables three-dimensional plotting capabilities for visualizing data in 3D space. Basic Steps Follow these steps to create a 3D subplot ? Import matplotlib and numpy libraries Create x, y and z data points Create a figure using plt.figure() Add a subplot with projection='3d' parameter Plot the 3D data using appropriate plotting methods Display the figure with plt.show() Example: Creating a 3D Line Plot Here's how to create a basic 3D line plot ? ...

Read More

How to create a 100% stacked Area Chart with Matplotlib?

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

A 100% stacked area chart displays data as percentages of the total, where each area shows the relative contribution of each category. In Matplotlib, we use stackplot() with percentage-normalized data to create this visualization. Understanding 100% Stacked Area Charts Unlike regular stacked area charts that show absolute values, a 100% stacked chart normalizes all values to percentages, making it easier to compare proportional relationships over time. Creating a 100% Stacked Area Chart Here's how to create a 100% stacked area chart showing world population distribution by continent ? import matplotlib.pyplot as plt import numpy ...

Read More

How to understand Seaborn's heatmap annotation format?

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

Seaborn's heatmap annotation format controls how numeric values are displayed on each cell of the heatmap. The fmt parameter accepts Python string formatting codes to customize the appearance of annotations. Basic Heatmap with Default Annotations Let's start with a simple heatmap to see default annotation behavior ? import seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt # Create sample data data = pd.DataFrame(np.random.random((4, 4)), columns=['A', 'B', 'C', 'D']) ...

Read More
Showing 141–150 of 902 articles
« Prev 1 13 14 15 16 17 91 Next »
Advertisements