Programming Articles

Page 363 of 2547

Creating multiple boxplots on the same graph from a dictionary, using Matplotlib

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

To create multiple boxplots on the same graph from a dictionary, we can use Matplotlib's boxplot() function. This is useful for comparing distributions of different datasets side by side. Basic Setup First, let's understand the steps involved ? Set the figure size and adjust the padding between and around the subplots Create a dictionary with multiple datasets Create a figure and a set of subplots Make a box and whisker plot using boxplot() Set the x-tick labels using set_xticklabels() method Display the figure using show() method Example Here's how to create multiple boxplots ...

Read More

How to edit the properties of whiskers, fliers, caps, etc. in a Seaborn boxplot in Matplotlib?

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

To edit the properties of whiskers, fliers, caps, and other elements in a Seaborn boxplot, you can access and modify these components after creating the plot. This allows you to customize colors, line styles, markers, and other visual properties. Basic Boxplot Creation First, let's create a basic boxplot and understand its components ? import seaborn as sns import pandas as pd import matplotlib.pyplot as plt # Create sample data df = pd.DataFrame({ 'values': [23, 45, 21, 15, 12, 18, 25, 30, 35, 40] }) # Create boxplot fig, ax = ...

Read More

How to force Matplotlib to show the values on X-axis as integers?

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

By default, Matplotlib may display decimal values on the X-axis when plotting data. To force the X-axis to show only integer values, you can use plt.xticks() with a range of integers or set a custom tick locator. Method 1: Using plt.xticks() with range() Create a range of integers based on your data's minimum and maximum values ? import math import matplotlib.pyplot as plt # Sample data x = [1.0, 1.75, 2.90, 3.15, 4.50, 5.50] y = [0.17, 1.17, 2.98, 3.15, 4.11, 5.151] plt.figure(figsize=(8, 5)) plt.plot(x, y, marker='o') # Force integer ticks on X-axis ...

Read More

How to plot certain rows of a Pandas dataframe using Matplotlib?

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

To plot certain rows of a Pandas DataFrame, you can use iloc[] to slice specific rows and then apply the plot() method. This is useful when you want to visualize only a subset of your data. Setting Up the Environment First, let's import the necessary libraries and create a sample DataFrame ? import matplotlib.pyplot as plt import numpy as np import pandas as pd # Set figure size for better visualization plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] = True # Create a DataFrame with random data np.random.seed(42) # For reproducible results df = pd.DataFrame(np.random.randn(10, ...

Read More

Moving X-axis in Matplotlib during real-time plot

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

To move X-axis in Matplotlib during real-time plot, we can create animations that dynamically adjust the X-axis limits as the plot updates. This technique is useful for creating scrolling plots or zooming effects in real-time data visualization. Steps to Move X-axis in Real-time Plot Set the figure size and adjust the padding between and around the subplots Create a figure and a set of subplots Create x and y data points using numpy Plot x and y data points using plot() method Make an animation by repeatedly calling a function animate that moves the X-axis during real-time ...

Read More

Dynamically updating a bar plot in Matplotlib

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

To update a bar plot dynamically in Matplotlib, we can create an animated visualization where bars change height and color over time. This is useful for creating engaging data visualizations or real-time data displays. Steps to Create Dynamic Bar Plot Set the figure size and adjust the padding between and around the subplots Create a new figure or activate an existing figure Make a list of data points and colors Plot the bars with data and colors, using bar() method Using FuncAnimation() class, make an animation by repeatedly calling a function that updates bar properties To display ...

Read More

How to draw more type of lines in Matplotlib?

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

To draw different types of lines in Matplotlib, you can customize line styles using various parameters like dashes, line width, and color. This allows you to create dashed, dotted, or custom dash patterns for better visualization. Steps to Draw Custom Lines Set the figure size and adjust the padding between and around the subplots Create x and y data points using NumPy Plot x and y data points using plot() method with custom line parameters To display the figure, use show() method Example − Custom Dash Pattern Here's how to create a line with ...

Read More

How to move the legend to outside of a Seaborn scatterplot in Matplotlib?

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

To move the legend outside of a Seaborn scatterplot, you need to use the bbox_to_anchor parameter in the legend() method. This allows precise control over legend positioning relative to the plot area. Basic Setup First, let's create a sample dataset and generate a scatterplot ? import matplotlib.pyplot as plt import pandas as pd import seaborn as sns # Set figure size plt.rcParams["figure.figsize"] = [8, 5] plt.rcParams["figure.autolayout"] = True # Create sample data df = pd.DataFrame({ 'x_values': [2, 1, 4, 3, 5, 2, 6], 'y_values': [5, 2, ...

Read More

How to set timeout to pyplot.show() in Matplotlib?

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

To set timeout to pyplot.show() in Matplotlib, you can use the figure's built-in timer functionality. This automatically closes the plot window after a specified duration. Basic Timeout Implementation Here's how to create a plot that closes automatically after 5 seconds ? import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() # Set the timer interval to 5000 milliseconds (5 seconds) timer = fig.canvas.new_timer(interval=5000) timer.add_callback(plt.close) plt.plot([1, 2, 3, 4, 5]) plt.ylabel('Y-axis Data') timer.start() plt.show() How It Works The process involves three key steps: ...

Read More

How to pass arguments to animation.FuncAnimation() in Matplotlib?

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

To pass arguments to animation.FuncAnimation() for a contour plot in Matplotlib, we can use the fargs parameter or create a closure. This allows us to pass additional data or parameters to the animation function. Basic Animation Example Let's start with a simple contour animation using random data ? import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # Create random data data = np.random.randn(800).reshape(10, 10, 8) fig, ax = plt.subplots(figsize=(7, 4)) def animate(i): ax.clear() ax.contourf(data[:, :, i]) ax.set_title(f'Frame {i}') ...

Read More
Showing 3621–3630 of 25,466 articles
« Prev 1 361 362 363 364 365 2547 Next »
Advertisements