Data Visualization Articles

Page 11 of 68

How to cycle through both colours and linestyles on a matplotlib figure?

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

To cycle through both colors and linestyles on a matplotlib figure, you can use the cycler module to combine multiple style properties. This creates automatic cycling through different combinations of colors and line styles for each plot. Steps Import matplotlib and the cycler module Set up figure parameters using rcParams Configure the property cycle with cycler() for colors and linestyles Plot multiple data series using plot() method Display the figure using show() method Example import matplotlib.pyplot as plt ...

Read More

How to better rasterize a plot without blurring the labels in matplotlib?

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

When creating plots in matplotlib, rasterization can help reduce file size for complex graphics, but it may blur text elements like labels. This tutorial shows how to rasterize plot elements while keeping labels crisp by selectively applying rasterization. Understanding Rasterization Rasterization converts vector graphics to bitmap images. While this reduces file size, it can blur text. The key is to rasterize only the plot data, not the labels ? Example: Comparing Rasterization Settings import matplotlib.pyplot as plt import numpy as np # Set figure size and layout plt.rcParams["figure.figsize"] = [10.00, 8.00] plt.rcParams["figure.autolayout"] = True ...

Read More

How to get the properties of a picked object in mplot3d (matplotlib + python)?

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

To get the properties of picked objects in matplotlib 3D, we can use event handling to capture mouse clicks on plot elements and extract their coordinates and other properties. Understanding Pick Events A pick event occurs when a user clicks on a pickable artist (like scatter points). The picker parameter defines the tolerance in points for picking. Creating a 3D Scatter Plot with Pick Events Here's how to create an interactive 3D scatter plot that displays coordinates when points are clicked ? import matplotlib.pyplot as plt import numpy as np # Set figure ...

Read More

How to plot a plane using some mathematical equation in matplotlib?

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

To plot a plane using a mathematical equation in matplotlib, you need to create a 3D surface plot. This involves generating coordinate grids and applying the plane equation to create the z-coordinates. Steps Import necessary libraries (NumPy and Matplotlib) Create x and y coordinate arrays using numpy.linspace() Generate a meshgrid from x and y coordinates Define the plane equation to calculate z values Create a 3D subplot using projection='3d' Plot the surface using plot_surface() Display the plot with plt.show() Basic Plane Equation A plane can be represented by the equation ax + by + ...

Read More

How to plot a bar chart for a list in Python matplotlib?

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

To plot a bar chart for a list in Python matplotlib, we can use the plt.bar() function. A bar chart displays categorical data with rectangular bars whose heights represent the values. Basic Bar Chart Here's how to create a simple bar chart from a list of values ? import matplotlib.pyplot as plt # List of data points data = [5, 3, 8, 2, 7, 4, 6] # Create bar chart plt.bar(range(len(data)), data) plt.xlabel('Categories') plt.ylabel('Values') plt.title('Bar Chart from List') plt.show() Bar Chart with Custom Labels You can add custom labels for better ...

Read More

Preserve padding while setting an axis limit in matplotlib

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

When setting axis limits in matplotlib, you might want to preserve padding around your plot for better visualization. This can be achieved by controlling the figure.autolayout parameter and manually adding padding to your axis limits. Understanding the Problem By default, matplotlib automatically adjusts the layout to fit all plot elements. However, when you set custom axis limits, this automatic adjustment might remove the desired padding around your data. Method 1: Disable Automatic Layout Set plt.rcParams["figure.autolayout"] = False to prevent matplotlib from automatically adjusting the layout − import numpy as np import matplotlib.pyplot as plt ...

Read More

How to show (0,0) on matplotlib graph at the bottom left corner?

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

When plotting data with matplotlib, the default axis limits might not show the origin (0, 0) at the bottom left corner. You can control this by setting explicit axis limits using xlim() and ylim() methods. Basic Example Here's how to ensure (0, 0) appears at the bottom left corner of your plot ? import numpy as np import matplotlib.pyplot as plt # Sample data points x = np.array([1, 2, 3, 4, 5]) y = np.array([2, 4, 1, 5, 3]) # Create the plot plt.figure(figsize=(8, 6)) plt.plot(x, y, 'bo-', linewidth=2, markersize=6) # Set axis ...

Read More

Graph k-NN decision boundaries in Matplotlib

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

k-NN (k-Nearest Neighbors) decision boundaries show how a k-NN classifier divides the feature space into regions for different classes. We can visualize these boundaries using matplotlib with contour plots and scatter plots. Understanding k-NN Decision Boundaries A decision boundary is the surface that separates different classes in the feature space. For k-NN, the boundary is determined by the majority vote of the k nearest neighbors for each point in the space. ...

Read More

How to make a mosaic plot in Matplotlib?

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

A mosaic plot is a graphical method for visualizing categorical data and relationships between variables. In Python, we can create mosaic plots using the statsmodels library along with Matplotlib. Installation Requirements First, install the required package ? pip install statsmodels The statsmodels package provides statistical computations and is essential for creating mosaic plots in Python. Basic Mosaic Plot Here's how to create a simple mosaic plot from a dictionary ? import matplotlib.pyplot as plt from statsmodels.graphics.mosaicplot import mosaic # Set figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ...

Read More

How to plot two violin plot series on the same graph using Seaborn?

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

To plot two violin plot series on the same graph using Seaborn, we can use the hue parameter in the violinplot() method. This allows us to create separate violin plots for different categories within the same visualization. Basic Violin Plot with Two Series The most straightforward approach is using the hue parameter to split data by a categorical variable ? import seaborn as sns import matplotlib.pyplot as plt # Set the figure size plt.figure(figsize=(10, 6)) # Load an example dataset tips = sns.load_dataset("tips") # Create a violin plot with two series using hue ...

Read More
Showing 101–110 of 680 articles
« Prev 1 9 10 11 12 13 68 Next »
Advertisements