In this blog post, I have discussed a list of 9 tips and tricks that you can use while working with matplotlib.

Originally Posted on my Website — Let’s Discuss Stuff

Tricks and Topics discussed in this blogpost:

How to change the figure size in matplotlib?

How to set axis limits in matplotlib?

How to set titles and labels in matplotlib?

How to download the plot you made?

How to add horizontal and vertical lines to the plot you made?

How to create a plot in log scale using matplotlib?

How to add a secondary axis to a plot in matplotlib?

How to add text annotation in a plot in matplotlib?

How to change the style and background color of a plot in matplotlib?

Matplotlib contains an argument figsize inside the plt.figure() the command to change the figure size of the plot. You have to pass the value of x and y as values to the argument.

If you pass (7,5) as an argument then matplotlib will create a plot which is 7 inches in length and 5 inches in breadth.

You can also use dpi the argument to change the value of dots per inch of your plot. More dpi will make the plot make crisper. The default value of dpi is 100.

#first you need to import all the required librariesimport numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as snsx = np.arange(0,5,0.2) # will create values from 0 to 5 at an interval of 0.2 each y = np.exp(x) + 10*np.sin(x) plt.plot(x,y)