Data Visualization Articles

Page 13 of 68

How to draw the largest polygon from a set of points in matplotlib?

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

To draw the largest polygon from a set of points in matplotlib, we need to find the convex hull of the points and then create a polygon patch. The convex hull gives us the outermost boundary that encloses all points, forming the largest possible polygon. Understanding Convex Hull A convex hull is the smallest convex polygon that contains all given points. Think of it as stretching a rubber band around all the points − the shape it forms is the convex hull. Finding the Largest Polygon We'll use scipy's ConvexHull to find the largest polygon from ...

Read More

How to change the face color of a plot using Matplotlib?

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

Matplotlib allows you to customize the background color of your plots using the set_facecolor() method. This is useful for creating visually appealing plots or matching specific design requirements. Basic Face Color Change The simplest way to change the face color is using the set_facecolor() method on the axes object ? import matplotlib.pyplot as plt import numpy as np # Create data points x = np.linspace(-10, 10, 100) y = np.sin(x) # Create figure and axes fig, ax = plt.subplots(figsize=(8, 4)) # Plot the data ax.plot(x, y, color='yellow', linewidth=3) # Set the face ...

Read More

Plotting a masked surface plot using Python, Numpy and Matplotlib

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

A masked surface plot allows you to hide or display only specific portions of 3D surface data based on certain conditions. This is useful when you want to exclude invalid data points or highlight specific regions of your surface. Setting Up the Environment First, we need to import the required libraries and configure the plot settings ? import matplotlib.pyplot as plt import numpy as np # Set figure size and layout plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True Creating the Coordinate Grid We'll create a coordinate grid using meshgrid to define our ...

Read More

How to set the border color of the dots in matplotlib's scatterplots?

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

To set the border color of dots in matplotlib scatterplots, use the edgecolors parameter in the scatter() method. This parameter controls the color of the dot borders, while linewidth controls their thickness. Basic Syntax plt.scatter(x, y, edgecolors='color_name', linewidth=width) Example with Red Border Here's how to create a scatterplot with red borders around the dots ? import numpy as np import matplotlib.pyplot as plt # Generate sample data N = 10 x = np.random.rand(N) y = np.random.rand(N) colors = np.random.rand(N) # Create scatterplot with red borders plt.scatter(x, y, s=500, c=colors, ...

Read More

Matplotlib – Date manipulation to show the year tick every 12 months

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

Matplotlib provides powerful date formatting capabilities for time series visualization. To display year ticks every 12 months with proper month labeling, we use YearLocator and MonthLocator with custom formatters. Understanding Date Locators and Formatters Matplotlib's date handling uses two key components: Locators − Determine where ticks are placed on the axis Formatters − Control how dates are displayed as text For year ticks every 12 months, we set major ticks for years and minor ticks for individual months. Complete Example Here's how to create a time series plot with year ticks showing ...

Read More

How to make a scatter plot for clustering in Python?

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

A scatter plot for clustering visualizes data points grouped by cluster membership, with cluster centers marked distinctly. This helps analyze clustering algorithms like K-means by showing how data points are distributed across different clusters. Basic Clustering Scatter Plot Here's how to create a scatter plot that shows clustered data points with their centers ? import numpy as np import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [8.00, 6.00] plt.rcParams["figure.autolayout"] = True # Generate sample data points x = np.random.randn(15) y = np.random.randn(15) # Assign cluster labels (0, 1, 2, 3 for ...

Read More

How do I put a circle with annotation in matplotlib?

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

To put a circle with annotation in matplotlib, we can create a visual highlight around a specific data point and add descriptive text with an arrow pointing to it. This is useful for drawing attention to important data points in plots. Steps to Create Circle with Annotation Here's the process to add a circled marker with annotation ? Set the figure size and adjust the padding between and around the subplots Create data points using numpy Get the point coordinate to put circle with annotation Get the current axis Plot the data points using plot() method ...

Read More

Creating 3D animation using matplotlib

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

To create a 3D animation using matplotlib, we can combine the power of mpl_toolkits.mplot3d for 3D plotting and matplotlib.animation for creating smooth animated sequences. Required Imports First, we need to import the necessary libraries ? import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation from mpl_toolkits.mplot3d import Axes3D # Set figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True Creating the Animation Function The animation function updates the 3D plot for each frame ? import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation from ...

Read More

How to set labels in matplotlib.hlines?

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

The matplotlib.hlines() function draws horizontal lines across the plot. To add labels to these lines, you can use the plt.text() method or create a legend by combining multiple hlines() calls with label parameters. Method 1: Using plt.text() for Direct Labels This approach places text labels directly next to the horizontal lines ? import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Add horizontal line with direct text label plt.hlines(y=1, xmin=1, xmax=4, lw=7, color='orange') plt.text(4, 1, 'y=1', ha='left', va='center', fontsize=12) # Add another horizontal line with ...

Read More

How to create broken horizontal bar graphs in matplotlib?

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

A broken horizontal bar graph displays data as horizontal bars with gaps or breaks, useful for showing discontinuous time periods, interrupted processes, or segmented data. Matplotlib's broken_barh() method creates these visualizations effectively. Syntax ax.broken_barh(xranges, yrange, **kwargs) Parameters xranges − List of (start, width) tuples defining horizontal segments yrange − Tuple (bottom, height) defining vertical position and height facecolors − Colors for each segment (single color or tuple of colors) Example Let's create a broken horizontal bar graph showing project timelines with interruptions ? import matplotlib.pyplot as plt ...

Read More
Showing 121–130 of 680 articles
« Prev 1 11 12 13 14 15 68 Next »
Advertisements