16 C
London
Friday, July 5, 2024
HomePythonMatplotlib in Python

Matplotlib in Python

How to Use abline Function in Matplotlib

The abline function in R can be used to add a straight line to a plot. Unfortunately this function doesn’t exist in Matplotlib, but we...

How to Modify a Matplotlib Histogram Color (With Examples)

You can use the following basic syntax to modify the color of a histogram in Matplotlib: plt.hist(data, color = "lightblue", ec="red") where: data: The name of the...

Display an Image as Grayscale in Matplotlib (With Example)

You can use the cmap argument in Matplotlib to easily display images on a grayscale. The following example shows how to use this argument in...

How to Set Axis Ticks in Matplotlib (With Examples)

You can use the following basic syntax to set the axis ticks in a Matplotlib plot: #set x-axis ticks (step size=2) plt.xticks(np.arange(min(x), max(x)+1, 2)) #set y-axis ticks...

How to Add Title to Subplots in Matplotlib (With Examples)

You can use the following basic syntax to add a title to a subplot in Matplotlib: ax.set_title('Subplot Title') The following examples shows how to use this...

How to Use fig.add_subplot in Matplotlib

You can use the following basic syntax to create subplots in Matplotlib: import matplotlib.pyplot as plt #define figure fig = plt.figure() #add first subplot in layout that has...

How to Reverse Axes in Matplotlib (With Examples)

You can use the following basic syntax to reverse the x-axis and y-axis in Matplotlib: plt.gca().invert_xaxis() plt.gca().invert_yaxis() The following example shows how to use this syntax in...

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Must read