Tuesday 5 September 2023

plot.show(): The Essential Step for Displaying Matplotlib Plots

When you define plot using Matplotlib library, those plot details are like lines, labels, colours, titles etc., are stored in in-memory, but these are not shown in the screen. To show the plot visually on the screen, you should call plot.show method.

 

plot_show_method.py

import matplotlib.pyplot as plt
import numpy as np

# Sample data
x1 = [5, 10, 15, 20, 25]
y1 = [20, 40, 60, 80, 100]

# Create a new figure with a specific size
plt.figure(figsize=(8, 6))

plt.plot(x1, y1, color='red')

plt.show()

 

Output

 

 


When ‘plot.show()’ method gets executed, it renders the plot visually on a window and make it visible on the screen.

 

Note

In case of interactive IDEs like Jupyter notebook, plot might be disaplyed without calling show method, but if you are running in standalone environment, then calling plot.show() method is mandatory to see the plot visually.


 

Previous                                                    Next                                                    Home

No comments:

Post a Comment