Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 23 of 102

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 to color a Seaborn boxplot based on DataFrame column name in Matplotlib?

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

To color a Seaborn boxplot based on DataFrame column names, you need to access the box artists and set their facecolor based on specific column conditions. This approach gives you fine−grained control over individual box colors. Basic Setup First, let's create a sample DataFrame and generate a basic boxplot ? import seaborn as sns import matplotlib.pyplot as plt import pandas as pd # Create sample data df = pd.DataFrame({ 'col1': [2, 4, 6, 8, 10, 3, 5], 'col2': [7, 2, 9, 1, 4, 8, 6] }) ...

Read More

How to draw rounded line ends using Matplotlib?

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

To draw rounded line ends using Matplotlib, we can use the solid_capstyle='round' parameter. This creates smooth, circular ends instead of the default square line caps, making your plots more visually appealing. Basic Rounded Line Example Let's start with a simple example showing the difference between default and rounded line caps ? import matplotlib.pyplot as plt import numpy as np # Create sample data x = np.linspace(0, 10, 5) y = np.sin(x) # Create the plot fig, ax = plt.subplots(figsize=(8, 4)) # Plot with rounded line ends ax.plot(x, y, linewidth=10, solid_capstyle='round', color='red', label='Rounded caps') ...

Read More

Plot 95% confidence interval errorbar Python Pandas dataframes in Matplotlib

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

To plot 95% confidence interval error bars with Python Pandas DataFrames in Matplotlib, we need to calculate the mean and standard error, then multiply by 1.96 for the 95% confidence interval. Understanding 95% Confidence Intervals A 95% confidence interval means we're 95% confident the true population mean lies within this range. For normally distributed data, we calculate it as: mean ± 1.96 × standard_error. Example Let's create a DataFrame and plot error bars with proper 95% confidence intervals ? import numpy as np import pandas as pd import matplotlib.pyplot as plt # Set ...

Read More

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 856 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 10K+ 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
Showing 221–230 of 1,016 articles
« Prev 1 21 22 23 24 25 102 Next »
Advertisements