'hold off' equivalent in python

  • Context: Python 
  • Thread starter Thread starter feynman1
  • Start date Start date
  • Tags Tags
    Equivalent Python
Click For Summary

Discussion Overview

The discussion centers around finding an equivalent to the 'hold off' functionality from MATLAB in Python, specifically in the context of plotting with libraries such as matplotlib. Participants explore how to manage multiple traces on the same plot and the appropriate methods to achieve the desired visual effects.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • Some participants inquire about the intent to draw multiple traces on the same plot, suggesting that it depends on the choice of plotting software.
  • It is noted that in matplotlib, the 'hold()' function is obsolete and no longer recognized, which raises questions about alternative methods.
  • A participant shares a code snippet demonstrating how to remove a collection of lines from a plot using the matplotlib library.
  • There is a suggestion to refer to the API documentation and use an IDE for better understanding of the arguments used by API methods.

Areas of Agreement / Disagreement

Participants express uncertainty about the current functionality of 'hold()' in matplotlib, with some agreeing that it is obsolete while others seek clarification on how to achieve the desired plotting behavior.

Contextual Notes

The discussion highlights limitations regarding the transition from MATLAB to Python plotting, particularly the differences in function availability and usage between the two environments.

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   Reactions: 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.
 
  • Sad
Likes   Reactions: jedishrfu
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   Reactions: Wrichik Basu and sysprog

Similar threads

  • · Replies 11 ·
Replies
11
Views
1K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 10 ·
Replies
10
Views
4K
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K