0
0
Matplotlibdata~3 mins

Inline display in Jupyter notebooks in Matplotlib

Choose your learning style9 modes available
Introduction

Inline display shows your plots directly inside the notebook. This helps you see results right after your code without opening new windows.

You want to quickly check a chart while exploring data.
You are sharing your notebook and want others to see plots easily.
You want to keep your work organized with plots embedded in your analysis.
You are teaching or presenting data visualizations step-by-step.
You want to save the notebook with plots visible for later review.
Syntax
Matplotlib
%matplotlib inline
This magic command tells Jupyter to show plots inside the notebook.
Run it once at the start of your notebook before plotting.
Examples
This example sets inline display, then plots a simple line chart.
Matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.show()
Here we create a bar chart that will appear inside the notebook.
Matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
plt.bar(['A', 'B', 'C'], [10, 20, 15])
plt.show()
Sample Program

This code sets the inline display, then plots square numbers with labels and title. The plot appears inside the notebook.

Matplotlib
%matplotlib inline
import matplotlib.pyplot as plt

# Create data
x = [0, 1, 2, 3, 4]
y = [0, 1, 4, 9, 16]

# Plot data
plt.plot(x, y)
plt.title('Square Numbers')
plt.xlabel('Number')
plt.ylabel('Square')
plt.show()
OutputSuccess
Important Notes

If you forget to run %matplotlib inline, plots may open in a separate window.

For interactive plots, other magics like %matplotlib notebook can be used.

Summary

Use %matplotlib inline to show plots inside Jupyter notebooks.

This makes your data visualization easy to see and share.

Run it once at the start before plotting.