How to have actual values in Matplotlib Pie Chart displayed?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 23:14:37

7K+ Views

To display actual values in a Matplotlib pie chart, you can use a custom autopct function that converts percentages back to the original values. This is useful when you want to show raw numbers instead of just percentages. Basic Example with Actual Values Here's how to display the actual values in your pie chart ? import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Data for the pie chart labels = ('Read', 'Eat', 'Sleep', 'Repeat') fracs = [5, 3, 4, 1] total = sum(fracs) explode = (0, ... Read More

How to plot MFCC in Python using Matplotlib?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 23:14:16

1K+ Views

MFCC (Mel-Frequency Cepstral Coefficients) are widely used features in audio processing and speech recognition. Python's python_speech_features library combined with Matplotlib allows us to extract and visualize these features effectively. What are MFCCs? MFCCs represent the shape of the spectral envelope of audio signals. They capture the most important characteristics of audio for speech recognition and audio analysis tasks. Installing Required Libraries First, install the necessary packages ? pip install python_speech_features matplotlib scipy numpy Step-by-Step Implementation Here's how to extract and plot MFCC features from an audio file ? from ... Read More

How can I convert from scatter size to data coordinates in Matplotlib?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 23:13:50

397 Views

Converting scatter plot marker sizes to data coordinates in Matplotlib helps you understand the actual data scale represented by marker sizes. This is useful for creating size legends or performing calculations based on visual marker dimensions. Basic Scatter Plot with Size Array First, let's create a scatter plot with different marker sizes ? import numpy as np import matplotlib.pyplot as plt # Set figure parameters plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create data points X = np.array([[1, 1], [2, 1], [2.5, 1]]) s = np.array([20, 10000, 10000]) # Create scatter plot ... Read More

How to load a .ttf file in Matplotlib using mpl.rcParams?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 23:13:28

566 Views

To load a custom .ttf file in Matplotlib using mpl.rcParams, you need to register the font with the font manager and set it as the default font family. This allows you to use custom fonts that aren't installed system-wide. Basic Font Loading Process The process involves these key steps − Import the required modules: pyplot and font_manager Create a FontProperties object from the .ttf file path Extract the font name using get_name() Set the font family in rcParams Apply the font to your plots Example Here's how to load and use a custom ... Read More

Scroll backwards and forwards through Matplotlib plots

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 23:13:10

2K+ Views

To scroll backward and forwards through Matplotlib plots using left and right arrow keys, we can bind a key press event to dynamically update the plot data. This technique is useful for creating interactive visualizations where users can navigate through different views of data. Steps to Create Scrollable Plots Set up the figure size and padding configuration Create initial data points using NumPy Define a key event handler function to respond to arrow keys Bind the key press event to the figure Add a subplot and plot the initial data Use show() to display the interactive plot ... Read More

How do you get the current figure number in Python's Matplotlib?

Vikram Chiluka
Updated on 25-Mar-2026 23:12:50

3K+ Views

In this article, we will learn how to get the current figure number in Python's Matplotlib. This is useful when working with multiple figures and you need to identify which figure is currently active. Matplotlib is a comprehensive plotting library for Python that provides MATLAB-like functionality. When working with multiple plots, each figure gets assigned a unique number that you can retrieve programmatically. Using plt.gcf().number What is plt.gcf()? The matplotlib.pyplot.gcf() function returns the current figure object. If no figure exists, it creates a new one automatically. matplotlib.pyplot.gcf() Example Here's how to ... Read More

How to increase the thickness of error line in a Matplotlib bar chart?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 23:12:30

2K+ Views

To increase the thickness of error lines in a Matplotlib bar chart, we can use the error_kw parameter with a dictionary containing line width properties. This parameter controls the appearance of error bars including their thickness, cap size, and cap thickness. Basic Bar Chart with Default Error Lines Let's first create a simple bar chart with default error lines ? import matplotlib.pyplot as plt # Sample data labels = ['G1', 'G2', 'G3', 'G4', 'G5'] values = [20, 35, 30, 35, 27] errors = [2, 3, 4, 1, 2] fig, ax = plt.subplots(figsize=(7.5, 3.5)) ... Read More

How to plot a time series array, with confidence intervals displayed in Python? (Matplotlib)

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 23:12:10

3K+ Views

To plot a time series with confidence intervals in Python, we can use Matplotlib's plot() for the main line and fill_between() for the confidence bands. This visualization helps show data uncertainty and trends over time. Step-by-Step Approach Here's how to create a time series plot with confidence intervals ? Create or load your time series data Calculate rolling mean and standard deviation Define upper and lower confidence bounds Plot the mean line using plot() Add confidence intervals using fill_between() Example import numpy as np import pandas as pd import matplotlib.pyplot as plt ... Read More

How to plot a watermark image in Matplotlib?

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 23:11:47

1K+ Views

A watermark is a semi-transparent image overlay that appears on top of your plot. Matplotlib provides the figimage() method to add watermark images directly to figures. Basic Watermark Example Here's how to add a watermark image to a matplotlib plot ? import numpy as np import matplotlib.pyplot as plt from matplotlib import cbook import matplotlib.image as image # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Load sample watermark image with cbook.get_sample_data('logo2.png') as file: watermark = image.imread(file) # Create plot fig, ax = plt.subplots() # ... Read More

Different X and Y scales in zoomed inset in Matplotlib

Rishikesh Kumar Rishi
Updated on 25-Mar-2026 23:11:24

1K+ Views

To show different X and Y scales in zoomed inset in Matplotlib, we can use the inset_axes() method from mpl_toolkits.axes_grid1.inset_locator. This allows us to create a magnified view of a specific region with custom scaling. Creating a Basic Inset with Different Scales Here's how to create a zoomed inset that focuses on a specific region of your plot ? import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.axes_grid1.inset_locator import mark_inset, inset_axes plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create data points x = np.linspace(0, 1, 100) y = x ** 2 ... Read More

Advertisements