Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 17 of 102

How to remove the digits after the decimal point in axis ticks in Matplotlib?

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

To remove the digits after the decimal point in axis ticks in Matplotlib, you can use several approaches. The most common methods involve formatting the tick labels to display only integer values. Method 1: Using set_xticklabels() with astype(int) This method converts the tick values to integers, effectively removing decimal places ? import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.array([1.110, 2.110, 4.110, 5.901, 6.00, 7.90, 8.90]) y = np.array([2.110, 1.110, 3.110, 9.00, 4.001, 2.095, 5.890]) fig, ax = plt.subplots() ax.plot(x, y) # Remove ...

Read More

Hiding major tick labels while showing minor tick labels in Matplotlib

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

To hide major tick labels while showing minor tick labels in Matplotlib, you can use the setp() method to control the visibility of specific tick label types. This is useful when you want a cleaner plot appearance with less cluttered labels. Basic Example Here's how to hide major tick labels while keeping minor ones visible ? import matplotlib.pyplot as plt import numpy as np # Set figure size plt.figure(figsize=(8, 4)) # Create data x = np.linspace(1, 10, 100) y = np.log(x) # Plot the data plt.plot(x, y, 'b-', linewidth=2) # Hide major ...

Read More

How to mark a specific level in a contour map on Matplotlib?

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

To mark a specific level in a contour map on Matplotlib, you can use the contour() method with specific level values and highlight them using different colors or line styles. This technique is useful for emphasizing particular data ranges or thresholds in your visualization. Basic Contour Plot with Labeled Levels First, let's create a basic contour plot and label the contour lines ? import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def f(x, y): return np.sin(x) ** 10 + np.cos(10 + y * ...

Read More

How to label a patch in matplotlib?

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

To label a patch in matplotlib, you need to add a label parameter when creating the patch and then use legend() to display it. This is useful for creating annotated plots with geometric shapes. Basic Patch Labeling Here's how to create and label a rectangle patch ? import matplotlib.pyplot as plt import matplotlib.patches as patches # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Initialize patch position x = y = 0.1 # Create figure and axis fig = plt.figure() ax = fig.add_subplot(111) # Add rectangle patch with label ...

Read More

How to sort bars in a bar plot in ascending order (Matplotlib)?

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

To sort bars in a bar plot in ascending order, we can take the following steps − Set the figure size and adjust the padding between and around the subplots. Make a list of data for bar plots. Create a bar plot using bar() method, with sorted data. To display the figure, use show() method. Example Here's how to create a bar plot with bars sorted in ascending order ? import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = [3, 5, 9, 15, 12] plt.bar(range(len(data)), sorted(data), ...

Read More

How to add titles to the legend rows in Matplotlib?

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

In Matplotlib, adding titles to legend rows helps organize multiple data series into logical groups. This technique uses phantom plot handles to create section headers within the legend. Basic Approach The key steps are creating phantom handles (invisible plot elements) and inserting them as section dividers in your legend ? import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample data y = np.exp(-np.arange(5)) markers = ["s", "o", "*"] labels = ["Series A", "Series B"] fig, ax = plt.subplots() # Plot multiple lines ...

Read More

What is the difference between importing matplotlib and matplotlib.pyplot?

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

When working with matplotlib, you have two main import options: importing the entire matplotlib package or just the matplotlib.pyplot module. Understanding the difference helps you write more efficient code. Importing matplotlib vs matplotlib.pyplot When you import matplotlib, you're importing the entire plotting library with all its modules and subpackages. However, importing matplotlib.pyplot only imports the pyplot interface, which provides a MATLAB-like plotting experience. # Importing entire matplotlib package import matplotlib # Importing only pyplot module import matplotlib.pyplot as plt Why Use matplotlib.pyplot? The pyplot module is the most commonly used interface because ...

Read More

What is the equivalent of Matlab's surf(x,y,z,c) in Matplotlib?

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

In MATLAB, surf(x, y, z, c) creates a 3D surface plot where the color is determined by the matrix c. In Matplotlib, the equivalent functionality is achieved using plot_surface() with appropriate parameters. Basic Surface Plot The simplest equivalent uses plot_surface() with a colormap − import matplotlib.pyplot as plt import numpy as np # Set figure properties plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure and 3D axis fig = plt.figure() ax = fig.add_subplot(projection='3d') # Generate data for a sphere u, v = np.mgrid[0:2 * np.pi:30j, 0:np.pi:20j] x = np.cos(u) * np.sin(v) ...

Read More

How to plot two histograms side by side using Matplotlib?

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

To plot two histograms side by side using Matplotlib, you can use subplots to create multiple plotting areas. This technique is useful for comparing distributions of different datasets visually. Basic Side-by-Side Histograms Here's how to create two histograms using pandas DataFrames ? import matplotlib.pyplot as plt import pandas as pd # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample data df1 = pd.DataFrame(dict(a=[1, 1, 1, 1, 3, 2, 2, 3, 1, 2])) df2 = pd.DataFrame(dict(b=[1, 1, 2, 1, 3, 3, 2, 2, 3, 1])) # Create subplots fig, ...

Read More

How to make a circular matplotlib.pyplot.contourf?

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

To create a circular matplotlib.pyplot.contourf plot, you need to generate data in a circular pattern and use contourf() with proper aspect ratio settings. This technique is useful for visualizing radial data patterns or creating circular heatmaps. Steps to Create Circular Contour Plot Set the figure size and adjust the padding between and around the subplots Create x, y, a, b and c data points using NumPy Create a figure and a set of subplots Make a contour plot using contourf() method Set the aspect ratios to maintain circular shape Display the figure using show() method ...

Read More
Showing 161–170 of 1,016 articles
« Prev 1 15 16 17 18 19 102 Next »
Advertisements