Data Visualization Articles

Page 10 of 68

Embedding a matplotlib animation into a tkinter frame

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

To embed a matplotlib animation into a tkinter frame, we need to combine matplotlib's animation capabilities with tkinter's GUI framework using the TkAgg backend. Key Components The integration requires several key components ? FigureCanvasTkAgg − Creates the canvas where matplotlib renders the figure NavigationToolbar2Tk − Provides zoom, pan, and navigation controls FuncAnimation − Handles the animation loop and frame updates Animation functions − init() and animate() functions to control the animation Complete Example Here's a complete example that creates an animated sine wave in a tkinter window ? import tkinter from ...

Read More

Saving multiple figures to one PDF file in matplotlib

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

To save multiple matplotlib figures in one PDF file, we can use the PdfPages class from matplotlib.backends.backend_pdf. This approach allows you to create multiple plots and combine them into a single PDF document. Basic Example Here's how to create two figures and save them to one PDF file − from matplotlib import pyplot as plt from matplotlib.backends.backend_pdf import PdfPages # Set figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create first figure fig1 = plt.figure() plt.plot([2, 1, 7, 1, 2], color='red', lw=5, label='Figure 1') plt.title('First Plot') plt.legend() # Create second figure ...

Read More

Aligning table to X-axis using matplotlib Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 26-Mar-2026 2K+ Views

The Python Matplotlib library allows us to create visual plots from given data. To make the data easier to read and relate to the chart, we can display it in the form of a table and position it directly below the corresponding bar chart. ...

Read More

How to plot int to datetime on X-axis using Seaborn?

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

When working with Seaborn plots, you may need to display integer timestamps as readable datetime labels on the X-axis. This is commonly required when dealing with Unix timestamps or other integer-based date representations. Understanding the Problem Integer timestamps (like Unix timestamps) are not human-readable. Converting them to datetime format on the X-axis makes your plots more interpretable and professional-looking. Complete Example Here's how to convert integer timestamps to datetime labels on the X-axis ? import seaborn as sns import matplotlib.pyplot as plt import pandas as pd import numpy as np # Set the ...

Read More

How to show numpy 2D array as grayscale image in Jupyter Notebook?

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

To show a NumPy 2D array as a grayscale image in Jupyter Notebook, you can use Matplotlib's imshow() function with the cmap='gray' parameter. This technique is commonly used for visualizing data matrices, image processing, and scientific computing. Basic Example Here's how to display a 2D array as a grayscale image ? import matplotlib.pyplot as plt import numpy as np # Create a 2D array with random values data = np.random.rand(5, 5) print("Array values:") print(data) # Display as grayscale image plt.imshow(data, cmap='gray') plt.title('2D Array as Grayscale Image') plt.colorbar() # Shows the value-to-color mapping plt.show() ...

Read More

Filling the region between a curve and X-axis in Python using Matplotlib

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

To fill the region between a curve and X-axis in Python using Matplotlib, we use the fill_between() method. This technique is useful for highlighting areas under curves, creating visualizations for statistical data, or emphasizing specific regions in plots. Basic Syntax The fill_between() method fills the area between two horizontal curves: plt.fill_between(x, y1, y2, where=None, alpha=None, color=None) Parameters x − Array of x-coordinates y1, y2 − Arrays defining the curves (y2 defaults to 0) where − Boolean condition to specify which areas to fill alpha − Transparency level (0-1) color − Fill color ...

Read More

How do I use colorbar with hist2d in matplotlib.pyplot?

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

To use colorbar with hist2d() in matplotlib, you need to capture the return value from hist2d() and pass the mappable object to colorbar(). The histogram returns a tuple containing the mappable object needed for the colorbar. Basic hist2d with Colorbar Here's how to create a 2D histogram with a colorbar ? import matplotlib.pyplot as plt import numpy as np # Generate sample data N = 1000 x = np.random.rand(N) y = np.random.rand(N) # Create 2D histogram fig, ax = plt.subplots(figsize=(8, 6)) h = ax.hist2d(x, y, bins=30) # Add colorbar using the mappable object ...

Read More

How to use unicode symbols in matplotlib?

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

Matplotlib supports Unicode symbols, allowing you to display special characters, mathematical symbols, and international text in your plots. You can use Unicode characters directly or through their escape codes. Basic Unicode Symbol Usage The simplest way is to use the Unicode escape sequence \u followed by the 4-digit hex code ? import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Unicode symbol - Greek Delta (Δ) plt.text(0.5, 0.5, s=u"\u0394", fontsize=50, ha='center', va='center') # Display the plot plt.show() This displays the Greek letter Delta ...

Read More

How to build colorbars without attached plot in matplotlib?

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

A colorbar in matplotlib is typically attached to a plot to show the color mapping. However, you can create standalone colorbars without any attached plot using ColorbarBase. This is useful for legends or reference scales. Creating a Basic Standalone Colorbar Use ColorbarBase to create a colorbar without an associated plot − import matplotlib.pyplot as plt import matplotlib as mpl # Set figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure and subplot fig, ax = plt.subplots() # Adjust layout to make room for colorbar fig.subplots_adjust(bottom=0.5) # Create normalization (data ...

Read More

How to append a single labeled tick to X-axis using matplotlib?

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

To append a single labeled tick to X-axis using matplotlib, you can use set_xticks() and set_xticklabels() methods to add a custom tick at any position on the axis. Steps Set the figure size and adjust the padding between and around the subplots. Create x and y data points using numpy. Plot x and y data points using plot() method. Set xticks at a single point. Set the tick label for single tick point. To display the figure, use show() method. Example import numpy as np import matplotlib.pyplot as plt # Set the ...

Read More
Showing 91–100 of 680 articles
« Prev 1 8 9 10 11 12 68 Next »
Advertisements