Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 12 of 102

How to fill rainbow color under a curve in Python Matplotlib?

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

Creating a rainbow gradient effect under a curve in Matplotlib involves using the fill_between() function with multiple color layers. This technique creates visually appealing plots by stacking colored regions with slightly different y-offsets. Basic Rainbow Fill Implementation The key is to plot multiple fill_between() layers, each with a different color and y-offset ? import numpy as np import matplotlib.pyplot as plt def plot_rainbow_under_curve(): rainbow_colors = ['violet', 'indigo', 'blue', 'green', 'yellow', 'orange', 'red'] x = np.linspace(-5, 5, 100) y = x ** 2 ...

Read More

How to draw axis lines inside a plot in Matplotlib?

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

In Matplotlib, you can draw axis lines inside a plot by positioning the spines at zero and hiding unnecessary borders. This creates a coordinate system where the x and y axes pass through the origin. Understanding Spines Spines are the lines connecting the axis tick marks that form the boundaries of the data area. By default, Matplotlib shows all four spines (top, bottom, left, right) around the plot area. Drawing Axis Lines Inside the Plot Here's how to position the axis lines at the center of the plot ? import numpy as np import ...

Read More

How to set same scale for subplots in Python using Matplotlib?

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

When creating subplots in Matplotlib, you often want them to share the same scale for better comparison. This is achieved using the sharex and sharey parameters when creating subplot arrangements. Using sharex Parameter The sharex parameter links the x-axis scale across subplots. When you zoom or pan one subplot, all linked subplots will follow ? import matplotlib.pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure fig = plt.figure() # Add subplots with shared x-axis ax1 = fig.add_subplot(2, 1, 1) ax2 ...

Read More

Conditional removal of labels in Matplotlib pie chart

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

To remove labels from a Matplotlib pie chart based on a condition, you can use a lambda function in the autopct parameter. This technique is useful when you want to display percentage labels only for slices that meet certain criteria, such as being above a specific threshold. Steps to Conditionally Remove Labels Set the figure size and adjust the padding between and around the subplots Create a Pandas DataFrame with your data Plot a pie chart using pie() method with conditional removal of labels Use a lambda function in autopct to show labels only when conditions are ...

Read More

Matplotlib – Make a Frequency histogram from a list with tuple elements in Python

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

To make a frequency histogram from a list with tuple elements in Python, we can extract the categories and frequencies from tuples and create a bar chart using Matplotlib. Steps to Create a Frequency Histogram Set the figure size and adjust the padding between and around the subplots Create a list of tuples containing category-frequency pairs Extract categories and frequencies by iterating through the data Create a bar plot using bar() method Display the figure using show() method Example Here's how to create a frequency histogram from tuple data ? import matplotlib.pyplot ...

Read More

How to rotate a simple matplotlib Axes?

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

To rotate a simple matplotlib axes, we can use the Affine2D transformation along with floating_axes. This technique creates a rotated coordinate system for plotting data at different angles. Required Imports First, import the necessary packages for creating rotated axes ? import matplotlib.pyplot as plt from matplotlib.transforms import Affine2D import mpl_toolkits.axisartist.floating_axes as floating_axes Steps to Rotate Axes The rotation process involves these key steps: Create an affine transformation − Define the rotation angle using Affine2D().rotate_deg() Set axis limits − Define the coordinate range for both x and y axes Create grid helper ...

Read More

How to add a 3d subplot to a matplotlib figure?

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

To add a 3D subplot to a matplotlib figure, you need to specify projection='3d' when creating the subplot. This enables three-dimensional plotting capabilities for visualizing data in 3D space. Basic Steps Follow these steps to create a 3D subplot ? Import matplotlib and numpy libraries Create x, y and z data points Create a figure using plt.figure() Add a subplot with projection='3d' parameter Plot the 3D data using appropriate plotting methods Display the figure with plt.show() Example: Creating a 3D Line Plot Here's how to create a basic 3D line plot ? ...

Read More

How to shift a column in a Pandas DataFrame?

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

The shift() method in Pandas allows you to shift the values in a column up or down by a specified number of positions. This is useful for creating lagged variables or aligning time series data. Syntax shift(periods=1, freq=None, axis=0, fill_value=None) Parameters periods − Number of positions to shift. Positive values shift down, negative values shift up. axis − 0 for shifting along rows (default), 1 for shifting along columns. fill_value − Value to use for filling the newly created missing positions. Basic Column Shifting Let's create a DataFrame and demonstrate ...

Read More

How to append two DataFrames in Pandas?

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

To append the rows of one DataFrame with the rows of another, we can use the Pandas append() function. With the help of append(), we can combine DataFrames vertically. Let's see how to use this method with examples. Note: The append() method is deprecated since Pandas 1.4.0. Use pd.concat() instead for new code. Steps to Append DataFrames Create two DataFrames with data Use append() method or pd.concat() to combine them Set ignore_index=True to reset row indices Handle different column names appropriately Example 1: Appending DataFrames with Same Columns When DataFrames have the same ...

Read More

How to get nth row in a Pandas DataFrame?

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

To get the nth row in a Pandas DataFrame, we can use the iloc[] method. For example, df.iloc[4] will return the 5th row because row numbers start from 0. Syntax df.iloc[n] Where n is the index position (0-based) of the row you want to access. Creating a Sample DataFrame Let's create a DataFrame with student information ? import pandas as pd df = pd.DataFrame({ 'name': ['John', 'Jacob', 'Tom', 'Tim', 'Ally'], 'marks': [89, 23, 100, 56, 90], 'subjects': ["Math", ...

Read More
Showing 111–120 of 1,016 articles
« Prev 1 10 11 12 13 14 102 Next »
Advertisements