Matplotlib Articles

Page 36 of 91

How to save an array as a grayscale image with Matplotlib/Numpy?

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

To save an array as a grayscale image with Matplotlib/NumPy, we can use imshow() with the gray colormap and savefig() to save the image to disk. Basic Example Here's how to create and save a grayscale image from a NumPy array ? import numpy as np import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create random data with 5x5 dimension arr = np.random.rand(5, 5) # Display as grayscale image plt.imshow(arr, cmap='gray') plt.colorbar() # Add colorbar to show intensity scale plt.title('Grayscale Image from Array') ...

Read More

How to label and change the scale of a Seaborn kdeplot's axes? (Matplotlib)

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

To label and change the scale of a Seaborn kdeplot's axes, we can customize both the axis labels and scale using matplotlib functions. This is useful for creating more informative and professionally formatted density plots. Basic Steps Set the figure size and adjust the padding between and around the subplots Create random data points using numpy Plot Kernel Density Estimate (KDE) using kdeplot() method Set axis scale and labels using matplotlib functions Display the figure using show() method Example Here's how to create a KDE plot with customized axis labels and scale ? ...

Read More

Plot curves in fivethirtyeight stylesheet in Matplotlib

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

The FiveThirtyEight stylesheet in Matplotlib provides a clean, professional look inspired by the popular data journalism website. This style features muted colors, subtle gridlines, and typography that makes charts publication-ready. Setting Up the FiveThirtyEight Style First, let's configure Matplotlib to use the FiveThirtyEight stylesheet ? import matplotlib.pyplot as plt import numpy as np # Configure figure settings plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Apply the FiveThirtyEight style plt.style.use('fivethirtyeight') print("FiveThirtyEight style applied successfully!") FiveThirtyEight style applied successfully! Creating Multiple Curves Now let's create three curves with ...

Read More

How to update the plot title with Matplotlib using animation?

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

To update the plot title with Matplotlib using animation, you can dynamically change the title text during each animation frame. This is useful for displaying real-time information or creating interactive visualizations. Basic Approach The key steps for animating plot titles are ? Set the figure size and adjust the padding between and around the subplots Create a new figure using figure() method Create x and y data points using numpy Get the current axis and add initial plot elements Define an animate function that updates the title for each frame Use FuncAnimation() to create the animation ...

Read More

Colouring the edges by weight in networkx (Matplotlib)

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

In NetworkX with Matplotlib, you can color graph edges based on their weights to create visually informative network visualizations. This technique helps highlight important connections and patterns in your network data. Basic Edge Coloring by Weight Here's how to create a directed graph with weighted edges and color them accordingly &#minus; import random as rd import matplotlib.pyplot as plt import networkx as nx # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create directed graph G = nx.DiGraph() G.add_nodes_from([1, 2, 3, 4]) G.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 1), (1, ...

Read More

Plotting animated quivers in Python using Matplotlib

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

To animate quivers in Python, we can create dynamic vector field visualizations using Matplotlib's FuncAnimation. This technique is useful for showing changing vector fields over time, such as fluid flow or electromagnetic fields. Steps to Create Animated Quivers Set the figure size and adjust the padding between and around the subplots Create x and y data points using numpy Create u and v data points using numpy for vector components Create a figure and a set of subplots Plot a 2D field of arrows using quiver() method To animate the quiver, change the u and v values ...

Read More

How to make markers on lines smaller in Matplotlib?

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

To make markers on lines smaller in Matplotlib, you can control marker size using the markersize parameter. This is useful when you want subtle markers that don't overwhelm your line plot. Basic Approach The key parameter for controlling marker size is markersize (or its shorthand ms). Smaller values create smaller markers ? import matplotlib.pyplot as plt import numpy as np # Create sample data x = np.linspace(0, 10, 20) y = np.sin(x) # Plot with small markers plt.figure(figsize=(8, 4)) plt.plot(x, y, 'o-', markersize=3, linewidth=1) plt.title('Line Plot with Small Markers (markersize=3)') plt.grid(True, alpha=0.3) plt.show() ...

Read More

Adjusting the heights of individual subplots in Matplotlib in Python

Farhan Muhamed
Farhan Muhamed
Updated on 25-Mar-2026 1K+ Views

Matplotlib is a powerful Python library for creating graphs and plots. When working with multiple subplots, you often need to adjust their individual heights to better display your data. This article demonstrates how to control subplot heights using two effective methods. Understanding Subplots A subplot is a smaller plot within a larger figure. You can arrange multiple subplots in rows and columns to compare different datasets or show related visualizations together. Figure with 4 Subplots (2×2) Subplot ...

Read More

How can I make Matplotlib.pyplot stop forcing the style of my markers?

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

When using matplotlib.pyplot, you may encounter situations where the default marker styling interferes with your desired appearance. To prevent matplotlib from forcing marker styles, you need to explicitly control marker properties and configuration settings. Setting Up the Plot Environment First, configure the figure parameters to ensure consistent marker rendering ? import matplotlib.pyplot as plt import numpy as np # Configure figure settings plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Generate sample data x = np.random.rand(20) y = np.random.rand(20) # Plot with explicit marker styling plt.plot(x, y, 'r*', markersize=10) plt.show() ...

Read More

Setting the limits on a colorbar of a contour plot in Matplotlib

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

When creating contour plots in Matplotlib, you can control the color range by setting limits on the colorbar. This allows you to focus on specific data ranges and maintain consistent color scales across multiple plots. Basic Approach To set colorbar limits on a contour plot, follow these steps ? Create coordinate data using NumPy Generate a meshgrid for contour plotting Set vmin and vmax parameters to define the color range Use contourf() with these limits Create a colorbar with ScalarMappable for custom ticks Example Here's how to create a contour plot with custom ...

Read More
Showing 351–360 of 902 articles
« Prev 1 34 35 36 37 38 91 Next »
Advertisements