The first Axes is not cleared with the cla() function. A Figure containing two Axes in different subplots. Only the second Axes is cleared with the cla() function: import matplotlib.pyplot as pltįigure 3. The following example creates a Figure and then plots two Axes in two different subplots. The elements within the Axes are not dropped, however the current Axes can be redrawn with commands in the same script. The () function clears the current Axes state without closing the Axes. An Axes has at least an X-Axis and a Y-Axis, and may have a Z-Axis. But it has the drawback that the formatter is now missing, and when you move the mouse on your plot you do not get the coordinates of the point the mouse is pointing to. It is the data plotting area in which most of the elements in a plot are located, including Axis, Tick, Line2D, Text, etc., and it also sets the coordinates. ax plt.gca () ax.tmajorformatter ( ()) plt.draw () +1 for tcaswell answer, I guess that's the standard way to do so. ![]() A Figure with the same elements cleared with the clf() function:Īxes is a container class within the top-level Figure container. ![]() A Figure not cleared with the clf() function:įigure 2. The following example shows how to create two identical Figures simultaneously, and then apply the clf() function only to Figure 2: import matplotlib.pyplot as pltįigure 1. 1 Answer Sorted by: 1 You can try this also: import matplotlib.pyplot as plt import numpy as np create data data1 np.random.rand (10, 10) data2 np.random.rand (10, 10) plot data fig, (ax1, ax2) plt.subplots (1, 2, figsize (8, 4), shareyTrue) ax1.imshow (data1) ax1.setylim (0,5) ax2.imshow (data2) plt. You can use the () function to clear the current Figure’s state. Figure includes everything visualized in a plot, including one or more Axes. Used to clear the current Axes state without closing it.įigure is the top-level container object in a matplotlib plot. Used to clear the current Figure’s state without closing it. There are two methods available for this purpose: This article focuses on how to clear a plot by clearing the current Axes and Figure state of a plot, without closing the plot window. ![]() Matplotlib’s pyplot API is stateful, which means that it stores the state of objects until a method is encountered that will clear the current state. Matplotlib is a data visualization and graphical plotting library for Python.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |