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
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

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