Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

How to show minor tick labels on a log-scale with Matplotlib?

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

In Matplotlib, displaying minor tick labels on a log-scale plot requires special formatting since log scales typically only show major ticks by default. We can achieve this by using the tick_params() method and FormatStrFormatter to control minor tick appearance. Basic Log-Scale Plot with Minor Ticks Here's how to create a log-scale plot and display minor tick labels ? import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import FormatStrFormatter # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create data points x = np.linspace(-2, 2, 10) y = np.exp(x) ...

Read More

How to fill the area under a step curve using pyplot? (Matplotlib)

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

To fill the area under a step curve using pyplot, you can use the fill_between() method with the step parameter. This creates filled regions beneath step plots, which are useful for displaying discrete data or histogram-like visualizations. Basic Step Curve with Fill Here's how to create a simple step curve with filled area ? 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 # Create data points x = np.linspace(-10, 10, 100) y1 = np.sin(x) y2 = np.cos(x) # Fill area under step ...

Read More

Boxplot with variable length data in Matplotlib

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

To make a boxplot with variable length data in Matplotlib, we can take the following steps − Set the figure size and adjust the padding between and around the subplots. Make a list of data points with different lengths. Make a box and whisker plot using boxplot() method. To display the figure, use show() method. Basic Example Here's how to create a boxplot with datasets of different lengths ? import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = [[2, 4, 1, 3], [0, 4, 3, 2], [0, ...

Read More

Saving all the open Matplotlib figures in one file at once

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

Matplotlib allows you to save multiple open figures into a single PDF file using the PdfPages class from matplotlib.backends.backend_pdf. This is useful when you want to create a multi-page report or documentation. Basic Approach To save all open Matplotlib figures in one PDF file, follow these steps: Create multiple figures using plt.figure() Plot data on each figure Use PdfPages to create a PDF file Get all figure numbers with plt.get_fignums() Save each figure to the PDF file Close the PDF file Example from matplotlib import pyplot as plt from matplotlib.backends.backend_pdf import PdfPages ...

Read More

How to plot collections.Counter histogram using Matplotlib?

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

To plot a histogram with collections.Counter, we can use the bar() method from Matplotlib. The Counter object automatically counts the frequency of each element, making it perfect for creating histograms from raw data. Basic Counter Histogram Here's how to create a simple histogram using Counter ? import collections from matplotlib import pyplot as plt # Sample data data = [0, 1, 2, 4, 1, 3, 0, 4, 1, 4, 3, 5, 6, 5, 2] # Count frequencies using Counter counter = collections.Counter(data) print("Counter object:", counter) # Create bar plot plt.figure(figsize=(8, 5)) plt.bar(counter.keys(), counter.values()) ...

Read More

How to show the title for the diagram of Seaborn pairplot() or PridGrid()? (Matplotlib)

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

To show the title for the diagram for Seaborn pairplot() or PairGrid(), we can use the fig.suptitle() method. This adds a centered title above all subplots in the figure. Steps Set the figure size and adjust the padding between and around the subplots Create a Pandas DataFrame with sample data Plot pairwise relationships using pairplot() or PairGrid() Add a centered title to the figure using fig.suptitle() Display the figure using show() method Example with pairplot() Here's how to add ...

Read More

How to check that pylab backend of Matplotlib runs inline?

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

To check that pylab/pyplot backend of Matplotlib runs inline, we can use the get_backend() method. This method returns the name of the current backend being used by Matplotlib for rendering plots. Checking the Current Backend The get_backend() method provides information about which backend Matplotlib is currently using ? import matplotlib backend = matplotlib.get_backend() print("Backend:", backend) Backend: Qt5Agg Checking for Inline Backend In Jupyter notebooks, you can verify if the inline backend is active by looking for specific backend names ? import matplotlib backend = matplotlib.get_backend() print("Current ...

Read More

How can I attach a pyplot function to a figure instance? (Matplotlib)

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

To attach a pyplot function to a figure instance, we can use figure() method and add an axes to it. This approach gives you more control over the figure and allows you to work with multiple subplots. Steps Set the figure size and adjust the padding between and around the subplots. Create a new figure or activate an existing figure using figure() method. Add an ~.axes.Axes to the figure as part of a subplot arrangement. Set a title to this axis using set_title() method. ...

Read More

How to add legend to imshow() in Matplotlib?

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

Adding a legend to imshow() in Matplotlib requires creating proxy artists since imshow() doesn't directly support legends. You can use plot() with invisible points or patches.Patch objects to create legend entries. Method 1: Using Invisible Plot Points Create invisible plot points with different colors to represent data ranges ? import numpy as np from matplotlib import pyplot as plt, cm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample data data = np.random.rand(3, 3) cmap = cm.YlOrBr # Get unique data values for legend unique_data = np.unique(data) # Create invisible plot ...

Read More

How to pause a pylab figure until a key is pressed or mouse is clicked? (Matplotlib)

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

To pause a pylab figure until a key is pressed or mouse is clicked, we can use Matplotlib's event handling system with button_press_event and key_press_event. Understanding Event Handling Matplotlib provides an interactive event system that can detect mouse clicks and key presses. We can bind callback functions to these events to control the animation flow. Basic Example: Mouse Click to Pause Here's how to create an animated plot that pauses when you click the mouse ? import matplotlib matplotlib.use("TkAgg") # Set backend before importing pyplot import matplotlib.pyplot as plt import numpy as np ...

Read More
Showing 4221–4230 of 61,298 articles
« Prev 1 421 422 423 424 425 6130 Next »
Advertisements