Data Visualization Articles

Page 56 of 68

How do you just show the text label in a plot legend in Matplotlib?

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

When creating matplotlib plots with legends, you might want to display only the text labels without the colored lines or markers. This can be achieved using specific parameters in the legend() method to hide the legend handles. Basic Approach To show only text labels in a plot legend, use the legend() method with these key parameters: handlelength=0 − Sets the length of legend handles to zero handletextpad=0 − Removes padding between handle and text fancybox=False − Uses simple rectangular legend box Example Here's how to create a plot with text-only legend labels ? ...

Read More

Box plot with min, max, average and standard deviation in Matplotlib

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

A box plot is an effective way to visualize statistical measures like minimum, maximum, average, and standard deviation. Matplotlib combined with Pandas makes it easy to create box plots from calculated statistics. Creating Sample Data and Statistics First, let's create random data and calculate the required statistics − import numpy as np import pandas as pd from matplotlib import pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create random dataset of 5x5 dimension data = np.random.randn(5, 5) print("Sample data shape:", data.shape) print("First few rows:") print(data[:3]) ...

Read More

Adding a scatter of points to a boxplot using Matplotlib

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

To add a scatter of points to a boxplot using Matplotlib, we can combine the boxplot() method with scatter() to overlay individual data points. This technique helps visualize both the distribution summary and actual data points. Steps Set the figure size and adjust the padding between and around the subplots. Create a DataFrame using DataFrame class with sample data columns. Generate boxplots from the DataFrame using boxplot() method. Enumerate through DataFrame columns to get x and y coordinates for scatter points. Add scatter points with slight horizontal jitter for better visibility. Display the figure using show() method. ...

Read More

How to center labels in a Matplotlib histogram plot?

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

To place the labels at the center in a histogram plot, we can calculate the mid-point of each patch and place the ticklabels accordingly using xticks() method. This technique provides better visual alignment between the labels and their corresponding histogram bars. Steps Set the figure size and adjust the padding between and around the subplots. Create a random standard sample data, x. Initialize a variable for number of bins. Use hist() method to make a histogram plot. ...

Read More

Show tick labels when sharing an axis in Matplotlib

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

When creating subplots that share an axis in Matplotlib, you might want to show tick labels on all subplots instead of hiding them on shared axes. By default, Matplotlib hides tick labels on shared axes to avoid redundancy, but you can control this behavior. Default Behavior with Shared Y-Axis When using sharey parameter, Matplotlib automatically hides y-axis tick labels on the right subplot to avoid duplication ? import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [10, 4] plt.rcParams["figure.autolayout"] = True # Create first subplot ax1 = plt.subplot(1, 2, 1) ax1.plot([1, 4, 9]) ax1.set_title('Left Plot') # ...

Read More

How to extract data from a Matplotlib plot?

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

To extract data from a plot in matplotlib, we can use get_xdata() and get_ydata() methods. This is useful when you need to retrieve the underlying data points from an existing plot object. Basic Data Extraction The following example demonstrates how to extract x and y coordinates from a matplotlib plot ? import numpy as np from matplotlib import pyplot as plt # Configure plot appearance plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample data y = np.array([1, 3, 2, 5, 2, 3, 1]) # Create plot and store line object curve, ...

Read More

How to plot complex numbers (Argand Diagram) using Matplotlib?

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

Complex numbers can be visualized using an Argand diagram, where the real part is plotted on the x-axis and the imaginary part on the y-axis. Matplotlib provides an excellent way to create these plots using scatter plots. Basic Argand Diagram Let's start by plotting a simple set of complex numbers ? import numpy as np import matplotlib.pyplot as plt # Create complex numbers complex_numbers = [1+2j, 3+1j, 2-1j, -1+3j, -2-2j] # Extract real and imaginary parts real_parts = [z.real for z in complex_numbers] imag_parts = [z.imag for z in complex_numbers] # Create the ...

Read More

Plotting multiple line graphs using Pandas and Matplotlib

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

To plot multiple line graphs using Pandas and Matplotlib, we can create a DataFrame with different datasets and use the plot() method to visualize multiple lines on the same graph. This approach is useful for comparing trends across different data series. Basic Setup First, let's set up the required libraries and configure the plot settings ? import pandas as pd import matplotlib.pyplot as plt # Set figure size for better visualization plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] = True Creating Sample Data We'll create a DataFrame with data for three different mathematical functions ...

Read More

How to show multiple colorbars in Matplotlib?

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

Creating multiple colorbars in Matplotlib allows you to visualize different datasets with their own color scales. This is particularly useful when displaying multiple subplots with different data ranges or when you want to compare datasets side by side. Steps to Create Multiple Colorbars To show multiple colorbars in matplotlib, we can take the following steps − Set the figure size and adjust the padding between and around the subplots. Create a figure and a set of subplots. Initialize a variable N for the number of sample data. Create random data1 using numpy. Display data as an ...

Read More

How to show Matplotlib in Flask?

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

Matplotlib plots can be displayed in Flask web applications by converting them to PNG images and serving them as HTTP responses. This approach uses BytesIO to handle the image data in memory without saving files to disk. Basic Flask Setup First, create a Flask application that serves a Matplotlib plot as a PNG image − import io from flask import Flask, Response from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure import numpy as np app = Flask(__name__) @app.route('/print-plot') def plot_png(): fig = Figure(figsize=(7.5, 3.5)) ...

Read More
Showing 551–560 of 680 articles
« Prev 1 54 55 56 57 58 68 Next »
Advertisements