- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I get interactive plots again in Spyder/Ipython/matplotlib?
To get interactive plots, we need to activate the figure. Using plt.ioff() and plt.ion(), we can perform interactive actions with plot.
Steps
Create fig and ax variables using subplots method, where default nrows and ncols are 1.
Draw a line, using plot() method.
Set the color of the line, i.e., orange.
Stopped the interaction, using plt.ioff() method.
To make the interaction plots, change the color of the line coordinate.
Start the interaction, using plt.ion() method.
Example
To use interactive plot in Ipython -
In [1]: %matplotlib auto Using matplotlib backend: GTK3Agg In [2]: import matplotlib.pyplot as plt In [3]: fig, ax = plt.subplots() # Diagram will get popped up, Let’s interact. In [4]: ln, = ax.plot(range(5)) # Drawing a line In [5]: ln.set_color('orange') # Changing drawn line to orange In [6]: plt.ioff() # Stopped interaction In [7]: ln.set_color('green') # Since we have stopped the interaction in the last step In [8]: plt.ion() # Started interaction
Output
- Related Articles
- How to display print statements interlaced with Matplotlib plots inline in iPython?
- How do I show the same Matplotlib figure several times in a single IPython notebook?
- How do I change the font size of the scale in Matplotlib plots?
- Best way to display Seaborn/Matplotlib plots with a dark iPython Notebook profile
- Displaying rotatable 3D plots in IPython or Jupyter Notebook
- How to get multiple overlapping plots with independent scaling in Matplotlib?
- How do I get all the bars in a Matplotlib bar chart?
- How get the (x,y) position pointing with mouse in an interactive plot (Python Matplotlib)?
- How to reuse plots in Matplotlib?
- Automatically run %matplotlib inline in IPython Notebook
- Matplotlib animation not working in IPython Notebook?
- How do we use Python in interactive mode?
- How to add annotations in Matplotlib Plots?
- How to set the matplotlib figure default size in ipython notebook?
- How do I make bar plots automatically cycle across different colors?

Advertisements