Data Visualization Articles

Page 27 of 68

How to modify a Matplotlib legend after it has been created?

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

Matplotlib legends can be modified after creation using various methods. You can change the title, position, styling, and other properties of an existing legend object. Basic Legend Modification First, let's create a basic plot with a legend and then modify it ? import matplotlib.pyplot as plt plt.figure(figsize=(8, 5)) # Create a plot with labels plt.plot([1, 3, 4, 5, 2, 1], [3, 4, 1, 3, 0, 1], label="line plot", color='red', linewidth=2) plt.plot([2, 4, 3, 6, 1, 2], [1, 2, 4, 2, 3, 1], ...

Read More

Plotting error bars from a dataframe using Seaborn FacetGrid (Matplotlib)

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

To plot error bars from a dataframe using Seaborn FacetGrid, we can create multi-panel plots with error bars for different subsets of data. This approach is useful when you want to visualize error bars across different categories or conditions. Basic Setup First, let's create a sample dataframe with multiple categories and error values ? import pandas as pd import seaborn as sns import matplotlib.pyplot as plt # Create sample data with categories data = { 'category': ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'], 'x_values': [1, ...

Read More

How can I get pyplot images to show on a console app? (Matplotlib)

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

When working with Matplotlib in console applications, you need to properly configure the backend and use pyplot.show() to display images. This is essential for viewing plots in terminal-based Python environments. Basic Setup First, ensure you have the correct backend configured for your console environment − import matplotlib matplotlib.use('TkAgg') # or 'Qt5Agg' depending on your system import matplotlib.pyplot as plt import numpy as np print("Backend:", matplotlib.get_backend()) Backend: TkAgg Displaying Images in Console Here's how to create and display a plot in a console application − import numpy ...

Read More

How to plot a function defined with def in Python? (Matplotlib)

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

To plot a function defined with def in Python, you need to create the function, generate data points, and use Matplotlib's plotting methods. This approach allows you to visualize mathematical functions easily. Basic Steps The process involves the following steps − Import necessary libraries (NumPy and Matplotlib) Create a user-defined function using def Generate x data points using NumPy's linspace() Plot the function using plot() method Display the plot using show() method Example Here's how to plot a custom mathematical function ? import numpy as np import matplotlib.pyplot as plt ...

Read More

How to produce a barcode in Matplotlib?

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

To produce a barcode in Matplotlib, you can create a visual representation using binary data (0s and 1s) where 1s represent black bars and 0s represent white spaces. This technique uses imshow() to display the binary pattern as a barcode-like image. Basic Barcode Creation Here's how to create a simple barcode using a binary array ? import matplotlib.pyplot as plt import numpy as np # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Binary pattern for barcode (1 = black bar, 0 = white space) code = np.array([ ...

Read More

How to handle times with a time zone in Matplotlib?

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

To handle times with a time zone in Matplotlib, we can use the pytz library along with Pandas datetime indexing. This approach ensures accurate timezone-aware plotting of time series data. Steps to Handle Timezone Data Import required libraries: pandas, numpy, matplotlib, and pytz Create a DataFrame with timezone-aware datetime index using pd.date_range() Use pytz.timezone() to specify the desired timezone Plot the data using DataFrame's plot() method Display the figure using plt.show() Example Here's how to create and plot timezone-aware data ? import pandas as pd import numpy as np from matplotlib import ...

Read More

How to change the default path for "save the figure" in Matplotlib?

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

To change the default path for "save the figure" in Matplotlib, you can use rcParams["savefig.directory"] to set the directory path. This allows you to specify where figures are saved by default without providing the full path each time. Setting Default Save Directory The most straightforward approach is to set the rcParams directory directly ? import matplotlib.pyplot as plt import numpy as np import os # Set default save directory plt.rcParams["savefig.directory"] = "/tmp" # Create sample data and plot data = np.random.rand(5, 5) plt.figure(figsize=(6, 4)) plt.imshow(data, cmap="viridis") plt.title("Sample Heatmap") plt.colorbar() # This will save ...

Read More

How to have actual values in Matplotlib Pie Chart displayed?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 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
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 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
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 382 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
Showing 261–270 of 680 articles
« Prev 1 25 26 27 28 29 68 Next »
Advertisements