Data Visualization Articles

Page 25 of 68

How can box plot be overlaid on top of swarm plot in Seaborn?

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

Overlaying a box plot on top of a swarm plot in Seaborn creates an effective visualization that combines individual data points with summary statistics. The swarm plot shows each data point while the box plot provides quartile information and outliers. Basic Overlay Example Here's how to create a box plot overlaid on a swarm plot using sample data − import seaborn as sns import matplotlib.pyplot as plt import pandas as pd import numpy as np # Set figure size plt.rcParams["figure.figsize"] = [8, 5] plt.rcParams["figure.autolayout"] = True # Create sample data np.random.seed(42) data = pd.DataFrame({ ...

Read More

Adjust the width of box in boxplot in Python Matplotlib

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

In Python Matplotlib, you can adjust the width of boxes in a boxplot using the widths parameter in the boxplot() method. This allows you to create boxes of different sizes for better visualization and comparison. Steps Set the figure size and adjust the padding between and around the subplots Create sample data using Pandas DataFrame Use the boxplot() method with the widths parameter to adjust box dimensions Display the plot using the show() method Example Here's how to create a boxplot with different box widths ? import pandas as pd import numpy ...

Read More

How to draw a heart with pylab?

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

Drawing a heart shape with pylab/matplotlib can be achieved using mathematical equations and the fill_between() method. This creates a beautiful heart visualization using parametric equations. Mathematical Approach The heart shape is created using two mathematical functions: Upper part: y1 = sqrt(1 - (abs(x) - 1)²) Lower part: y2 = -3 * sqrt(1 - (abs(x) / 2)^0.5) Steps Set the figure size and adjust the padding between and around the subplots. Create x, y1 and y2 data points using numpy. Fill the area between (x, y1) and (x, y2) using fill_between() method. Place ...

Read More

How do I show the same Matplotlib figure several times in a single IPython notebook?

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

To show the same Matplotlib figure several times in a single Jupyter notebook, you can use the fig.show() method or plt.show(). This is useful when you want to display the same plot multiple times at different points in your notebook. Basic Approach Using fig.show() Create a figure once and display it multiple times using the figure's show method ? import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure and plot data fig, ax = plt.subplots() ax.plot([2, 4, 7, 5, 4, 1]) ax.set_title('Sample Line Plot') ...

Read More

How to plot sine curve on polar axes using Matplotlib?

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

To plot a sine curve on polar axes using Matplotlib, we need to create a polar coordinate system and plot angular data. Polar plots are useful for representing periodic data and circular patterns. Steps to Create a Polar Sine Plot Set the figure size and adjust the padding between and around the subplots Create a new figure using figure() method Add polar axes using add_subplot(projection='polar') Generate angular data points (theta) and radius values using numpy Plot the data using plot() method on polar axes Display the figure using show() method Example import numpy ...

Read More

How do I find the intersection of two line segments in Matplotlib?

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

To find the intersection of two line segments in Matplotlib, we calculate where two lines meet using their slopes and intercepts, then draw horizontal and vertical lines through that point. Mathematical Formula For two lines with equations y = m1*x + c1 and y = m2*x + c2, the intersection point is: x_intersection = (c1 - c2) / (m2 - m1) y_intersection = m1 * x_intersection + c1 Example Here's how to find and visualize the intersection point ? import matplotlib.pyplot as plt import numpy as np ...

Read More

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 8K+ 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 708 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
Showing 241–250 of 680 articles
« Prev 1 23 24 25 26 27 68 Next »
Advertisements