- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
When is plt.Show() required to show a plot and when is it not?
plt.Show() would help whenever there is no interactive plot.
fig.Show() would help to display all the figures if it is interactive.
Let's take an example to observe the difference between plt.Show() and fig.Show().
Open iPython shell.
Set the figure size and adjust the padding between and around the subplots.
Create a new figure or activate an existing figure.
Plot a line using plot() method.
Display the figure using Show() method.
To display the figure, use Show() method with block=False.
import numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a new figure fig = plt.figure() # Plot a line plt.plot(np.linspace(-5, 5, 100)) fig.show() plt.show(block=False)
It will produce the following output −
You would get this output only in interactive mode. plt.Show() with block=True would show the output when there is no interactive plot.
- What is training? When and why it is needed?
- How faster is the time when we think of something and Google will show results?
- Is `definer` required when creating a MySQL stored procedure?
- What is a psychometric test? When is it conducted?
- Show tick labels when sharing an axis in Matplotlib
- When to use inline function and when not to use it in C/C++?
- When to use new operator in C++ and when it should not be used?
- What is a lunar eclipse? When does it occur?
- Why SHOW DBS does not show my databases in MongoDB?
- Difference between SHOW INDEX, SHOW INDEXES and SHOW KEYS in MySQL?
- What is a ClassCastException and when it will be thrown in Java?
- MongoDB difference between show dbs and show databases?
- Where is the MySQL database gets saved when it is created?
- What is a smart pointer and when should I use it in C++?