'hold off' equivalent in python

In summary, When using libraries like matplotlib in Python, it is possible to draw multiple traces on the same plot, but the specific method may vary depending on the library. The API documentation provided by the developers should be consulted and using an IDE can also be helpful. The old method of using hold() is no longer recognized and has been replaced.
  • #1
feynman1
435
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
  • #3
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.
 
  • #4
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
  • #5
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.
 
  • Sad
Likes jedishrfu
  • #6
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

FAQ: 'hold off' equivalent in python

What is the 'hold off' equivalent in Python?

The 'hold off' equivalent in Python is the pass statement. It is used as a placeholder and does nothing, allowing the code to continue without throwing an error.

When should I use the 'hold off' equivalent in Python?

The pass statement should be used when a statement is required syntactically, but no action is needed. This can be useful in situations such as defining empty classes or functions that will be filled in later.

How is the 'hold off' equivalent different from a comment in Python?

A comment is used to provide information or explanation to a human reader, whereas the pass statement is a valid line of code that has no effect on the program's execution. Comments are usually ignored by the interpreter, while pass statements are executed.

Can I use the 'hold off' equivalent multiple times in my code?

Yes, you can use the pass statement multiple times in your code. However, it is important to note that using too many pass statements can make your code difficult to read and maintain.

Is there an alternative to the 'hold off' equivalent in Python?

Yes, there is an alternative to the pass statement in Python. You can also use the Ellipsis object, which is represented by three consecutive dots (...). Like pass, it does nothing and can be used as a placeholder in code.

Similar threads

Replies
10
Views
2K
Replies
9
Views
3K
Replies
5
Views
1K
Replies
17
Views
2K
Replies
2
Views
997
Replies
1
Views
1K
Replies
1
Views
1K
Replies
9
Views
2K
Replies
3
Views
2K
Replies
47
Views
3K
Back
Top