Articles on Trending Technologies

Technical articles with clear explanations and examples

How to plot thousands of circles quickly in Matplotlib?

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

When plotting thousands of circles in Matplotlib, using individual Circle patches becomes very slow. The efficient approach is to use CircleCollection from matplotlib.collections, which renders all circles in a single operation. Why Use CircleCollection? CircleCollection is optimized for rendering many similar shapes at once. Instead of creating thousands of individual patches, it handles all circles as a single collection, dramatically improving performance. Basic Implementation import numpy as np import matplotlib.pyplot as plt import matplotlib.collections as mc # Generate random data for 1000 circles num_circles = 1000 sizes = 50 * np.random.random(num_circles) positions = 10 ...

Read More

How to plot a time series graph using Seaborn or Plotly?

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

Time series graphs help visualize data changes over time. Seaborn and Plotly are powerful Python libraries that make creating time series plots straightforward and visually appealing. Using Seaborn for Time Series Plot Seaborn's lineplot() function creates clean time series visualizations with minimal code ? import seaborn as sns import matplotlib.pyplot as plt import pandas as pd import numpy as np # Set figure size plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] = True # Create sample time series data df = pd.DataFrame({ 'time': pd.date_range("2021-01-01 12:00:00", periods=10, freq="30min"), 'speed': ...

Read More

How to make a rug plot in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 903 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 795 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 644 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
Showing 1–10 of 61,303 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements