Matplotlib is a Python library that helps in drawing graphs. It is used in data visualization and graph plotting. Matplotlib Inline is a package that supports Matplotlib to display plots directly inline and save them to notebooks. In this article, we’ll cover the following:
Matplotlib Without inline
The %matplotlib inline enables “inline plotting”, where plotted graphics appear in your notebook. Suppose we want to draw a simple line graph using the following code. The code works fine, but it doesn’t show the line graph inline with the code.
Python3
import matplotlib.pyplot as plt # creating list of Month and Share_buy for Plotting Line graph Month = [ 'January' , 'February' , 'March' ] Share_buy = [ 10 , 17 , 30 ] # plotting line plot plt.title( "Share's Buy in a month" ) plt.plot(Month, Share_buy) |
Output:
Matplotlib With inline
To solve the above problem, we can use the %matplotlib inline command before creating the line graph. The code runs correctly without any errors again and the plots appear inline in the notebook.
Python3
% matplotlib inline import matplotlib.pyplot as plt #creating list of Month and Share_buy for Plotting Line graph Month = [ 'January' , 'February' , 'March' ] Share_buy = [ 10 , 17 , 30 ] #plotting line plot plt.title( "Share's Buy in a month" ) plt.plot(Month, Share_buy) |
Output: