Python 'hold off' equivalent in python

  • Thread starter Thread starter feynman1
  • Start date Start date
  • Tags Tags
    Equivalent Python
AI Thread Summary
In Python, specifically when using the matplotlib library, the 'hold' function is obsolete and cannot be used as it was in MATLAB. Instead, to manage multiple traces on the same plot, one can use the `remove()` method on the plot object. For instance, after plotting a line, you can store the plot object and call `remove()` to erase it before drawing another trace. It is also recommended to consult the matplotlib API documentation for guidance on plotting methods and to utilize an IDE for better understanding of the arguments used in these methods. This approach allows for sequentially displaying multiple traces on the same graph.
feynman1
Messages
435
Reaction score
29
In MATLAB one can 'hold off' to remove a previously drawn thing on the same graph. How about in python?
 
Last edited:
Technology news on Phys.org
jedishrfu said:
Your intent is to draw multiple traces on the same plot?

It would depend on the choice of plotting software accessed by python. A common one is matplotlib where it is possible. These examples may help:

https://www.programcreek.com/python/example/56588/matplotlib.pyplot.hold
Thanks very much. I want to draw 2 things in the same graph and show them 1 at a time (1st appears, 1st vanishes, 2nd appears...). I used plt.hold('off') but it was reported as an error.
 
When you are using a library like matplotlib you should refer to the API documentation provided by the developers. Using an IDE also helps as it will describe the arguments used by API methods.
 
  • Like
Likes sysprog and jedishrfu
pbuk said:
When you are using a library like matplotlib you should refer to the API documentation provided by the developers. Using an IDE also helps as it will describe the arguments used by API methods.
Seems that hold(), obsolete, is no longer recognized.
 
Python:
from matplotlib import pyplot as plt
# Note the , in the next line: pyplot.plot returns a list and we
# want the first element which is a collection of 2DLines.
currentPlot, = plt.plot([1, 4, 9, 16])
# This will remove the collection of lines from the plot.
currentPlot.remove()
 
  • Like
  • Informative
Likes Wrichik Basu and sysprog
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
hi; i purchased 3 of these, AZDelivery 3 x AZ-MEGA2560-Board Bundle with Prototype Shield and each is reporting the error message below. I have triple checked every aspect of the set up and all seems in order, cable devices port, board reburn bootloader et al . I have substituted an arduino uno and it works fine; could you help please Thanks Martyn 'avrdude: ser_open(): can't set com-state for "\\.\COM3"avrdude: ser_drain(): read error: The handle is invalid.avrdude: ser_send(): write...

Similar threads

Replies
11
Views
1K
Replies
2
Views
809
Replies
10
Views
3K
Replies
9
Views
3K
Replies
5
Views
2K
Replies
2
Views
1K
Back
Top