Matplotlib Articles

Page 41 of 91

Adding units to heatmap annotation in Seaborn

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

To add units to a heatmap annotation in Seaborn, we can customize the text annotations after creating the heatmap. This is useful for displaying data with specific units like percentages, currency, or measurements. Steps to Add Units Set the figure size and adjust the padding between and around the subplots. Create a 5×5 dimension matrix using NumPy. Plot rectangular data as a color-encoded matrix. Annotate heatmap values with %age unit. To display the figure, use show() method. Example Here's how to create a heatmap and add percentage units to the annotations − ...

Read More

How to color a Matplotlib scatterplot using a continuous value?

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

To color a matplotlib scatterplot using continuous values, we can map a third variable to the color of each point. This creates a visual representation where color intensity or hue represents the magnitude of the continuous variable. Basic Scatterplot with Continuous Coloring Here's how to create a scatter plot where colors represent continuous values ? import numpy as np import matplotlib.pyplot as plt # Set figure size and layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Generate random data points x, y, z = np.random.rand(3, 50) # Create figure and subplots f, ...

Read More

Text alignment in a Matplotlib legend

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

Text alignment in a Matplotlib legend allows you to control how the legend text is positioned. You can set horizontal alignment using the set_ha() method on legend text objects. Basic Legend Text Alignment Here's how to align legend text to the left ? import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-5, 5, 100) plt.plot(x, np.sin(x), label="$y=sin(x)$") plt.plot(x, np.cos(x), label="$y=cos(x)$") legend = plt.legend(loc='upper right') for t in legend.get_texts(): t.set_ha('left') plt.show() Different Alignment Options You ...

Read More

Plot Matplotlib 3D plot_surface with contour plot projection

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

To create a 3D surface plot with contour projections in Matplotlib, we combine plot_surface() for the main surface and contourf() for projecting contours onto the coordinate planes. Understanding the Components A surface plot with contour projections consists of: A 3D surface using plot_surface() Contour projections on the XY, XZ, and YZ planes using contourf() The zdir parameter controls which plane the contour is projected onto Basic Example Here's how to create a surface plot with contour projections ? import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import ...

Read More

How to add Matplotlib Colorbar Ticks?

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

A colorbar in Matplotlib displays the color scale used in a plot. By default, Matplotlib automatically places ticks on the colorbar, but you can customize these ticks to show specific values or improve readability. Basic Colorbar with Custom Ticks Here's how to add custom ticks to a colorbar using np.linspace() ? 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 data x, y = np.mgrid[-1:1:100j, -1:1:100j] z = (x + y) * np.exp(-5.0 * (x ** 2 + y ** 2)) ...

Read More

How to change the font properties of a Matplotlib colorbar label?

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

To change the font properties of a Matplotlib colorbar label, you can customize the label using various font parameters like weight, size, and family. Here's how to modify colorbar label properties effectively. Steps to Change Colorbar Label Font Properties Set the figure size and adjust the padding between and around the subplots. Create x, y and z data points using numpy. Use imshow() method to display the data as an image, i.e., on a 2D regular raster. Create a colorbar for a ScalarMappable instance, mappable. Using colorbar axes, set the font properties such that the label is ...

Read More

How can I draw a scatter trend line using Matplotlib?

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

To draw a scatter trend line using Matplotlib, we can use polyfit() and poly1d() methods to calculate and plot the trend line over scattered data points. Basic Scatter Plot with Trend Line Here's how to create a scatter plot with a linear trend line − 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 sample data x = np.random.rand(100) y = np.random.rand(100) # Create scatter plot fig, ax = plt.subplots() ax.scatter(x, y, c=x, cmap='plasma', alpha=0.7) # Calculate trend line using ...

Read More

How to plot hexbin histogram in Matplotlib?

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

A hexbin histogram in Matplotlib displays the distribution of two-dimensional data using hexagonal bins. This visualization is particularly useful for large datasets where traditional scatter plots become cluttered with overlapping points. Basic Hexbin Plot The hexbin() method creates a hexagonal binning plot where the color intensity represents the density of data points in each hexagon ? import numpy as np import matplotlib.pyplot as plt # Generate sample data x = 2 * np.random.randn(5000) y = x + np.random.randn(5000) # Create hexbin plot fig, ax = plt.subplots(figsize=(8, 6)) hb = ax.hexbin(x[::10], y[::10], gridsize=20, cmap='plasma') ...

Read More

How to make joint bivariate distributions in Matplotlib?

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

Joint bivariate distributions visualize the relationship between two continuous variables. In Matplotlib, we can create these distributions using scatter plots with transparency to show density patterns. Basic Joint Bivariate Distribution Here's how to create a simple joint bivariate distribution using correlated data − import numpy as np import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [8, 6] plt.rcParams["figure.autolayout"] = True # Generate correlated data np.random.seed(42) x = 2 * np.random.randn(5000) y = x + np.random.randn(5000) # Create scatter plot fig, ax = plt.subplots() scatter = ax.scatter(x, y, alpha=0.08, c=x, cmap="viridis") ...

Read More

How to align the bar and line in Matplotlib two Y-axes chart?

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

To align bar and line plots in matplotlib with two Y-axes, we use the twinx() method to create a twin axis that shares the X-axis but has an independent Y-axis. This allows overlaying different chart types on the same plot. Creating DataFrame and Basic Setup First, let's create sample data and set up the figure parameters ? import matplotlib.pyplot as plt import pandas as pd # Set figure size and layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample DataFrame df = pd.DataFrame({"col1": [1, 3, 5, 7, 1], "col2": [1, 5, 7, ...

Read More
Showing 401–410 of 902 articles
« Prev 1 39 40 41 42 43 91 Next »
Advertisements