本文整理匯總了Python中matplotlib.pyplot.fignum_exists方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.fignum_exists方法的具體用法?Python pyplot.fignum_exists怎麽用?Python pyplot.fignum_exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.fignum_exists方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_figure
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import fignum_exists [as 別名]
def test_figure(self):
writer = SummaryWriter()
figure, axes = plt.figure(), plt.gca()
circle1 = plt.Circle((0.2, 0.5), 0.2, color='r')
circle2 = plt.Circle((0.8, 0.5), 0.2, color='g')
axes.add_patch(circle1)
axes.add_patch(circle2)
plt.axis('scaled')
plt.tight_layout()
writer.add_figure("add_figure/figure", figure, 0, close=False)
assert plt.fignum_exists(figure.number) is True
writer.add_figure("add_figure/figure", figure, 1)
assert plt.fignum_exists(figure.number) is False
writer.close()
示例2: test_figure_list
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import fignum_exists [as 別名]
def test_figure_list(self):
writer = SummaryWriter()
figures = []
for i in range(5):
figure = plt.figure()
plt.plot([i * 1, i * 2, i * 3], label="Plot " + str(i))
plt.xlabel("X")
plt.xlabel("Y")
plt.legend()
plt.tight_layout()
figures.append(figure)
writer.add_figure("add_figure/figure_list", figures, 0, close=False)
assert all([plt.fignum_exists(figure.number) is True for figure in figures])
writer.add_figure("add_figure/figure_list", figures, 1)
assert all([plt.fignum_exists(figure.number) is False for figure in figures])
writer.close()
示例3: redraw
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import fignum_exists [as 別名]
def redraw(self):
"""
Redraw plot. Use after custom user modifications of axes & fig objects
"""
if plt.isinteractive():
fig = self.kwargs['fig']
#Redraw figure if it was previously closed prior to updating it
if not plt.fignum_exists(fig.number):
fig.show()
fig.canvas.draw()
else:
print('redraw() is unsupported in non-interactive plotting mode!')
示例4: test_fignum_exists
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import fignum_exists [as 別名]
def test_fignum_exists():
# pyplot figure creation, selection and closing with fignum_exists
plt.figure('one')
plt.figure(2)
plt.figure('three')
plt.figure()
assert plt.fignum_exists('one')
assert plt.fignum_exists(2)
assert plt.fignum_exists('three')
assert plt.fignum_exists(4)
plt.close('one')
plt.close(4)
assert not plt.fignum_exists('one')
assert not plt.fignum_exists(4)
示例5: is_open
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import fignum_exists [as 別名]
def is_open(self) -> bool:
"""Returns True if the figure window is open."""
return plt.fignum_exists(self.fig.number)
示例6: display
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import fignum_exists [as 別名]
def display(self, image):
if self.imsh is None or not plt.fignum_exists(self.imsh.figure.number):
self.imsh = plt.imshow(image, interpolation='nearest')
self.imsh.axes.axis('off')
self.imsh.axes.set_position((0, 0, 1, 1))
self.imsh.figure.canvas.draw()
else:
self.imsh.set_data(image)
plt.pause(1e-4)
示例7: plot_process
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import fignum_exists [as 別名]
def plot_process(queue,
name,
labels=None,
x_scale='linear',
y_scale='linear'):
"""Grabs data from the queue and plots it in a named figure
"""
# Set up the figure and display it
fig = setup_figure(name)
plt.show(block=False)
if labels is not None:
plt.xlabel(labels[0])
plt.ylabel(labels[1])
plt.xscale(x_scale)
plt.yscale(y_scale)
while True:
# Get all the data currently on the queue
data = []
while not queue.empty():
data.append(queue.get())
# If there is no data, no need to plot, instead wait for a
# while
if len(data) == 0 and plt.fignum_exists(fig.number):
plt.pause(0.015)
continue
# Check if poison pill (None) arrived or the figure was closed
if None in data or not plt.fignum_exists(fig.number):
# If yes, close the figure and leave the process
plt.close(fig)
break
else:
# Plot the data, then wait 15ms for the plot to update
for datum in data:
plt.plot(*datum[0], **datum[1])
plt.pause(0.015)
示例8: test_log_mpl_plotly
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import fignum_exists [as 別名]
def test_log_mpl_plotly(self):
assert (
os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.CHART))
is False
)
assert (
os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.CHART))
is False
)
figure, axes = plt.figure(), plt.gca()
circle1 = plt.Circle((0.2, 0.5), 0.2, color="r")
circle2 = plt.Circle((0.8, 0.5), 0.2, color="g")
axes.add_patch(circle1)
axes.add_patch(circle2)
plt.axis("scaled")
plt.tight_layout()
with patch("polyaxon.tracking.run.Run._log_has_events") as log_dashboard:
self.run.log_mpl_plotly_chart(name="figure", figure=figure, step=1)
assert log_dashboard.call_count == 1
self.event_logger.flush()
assert (
os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.CHART))
is False
)
assert (
os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.CHART))
is True
)
events_file = get_event_path(
self.run_path, kind=V1ArtifactKind.CHART, name="figure"
)
assert os.path.exists(events_file) is True
results = V1Events.read(kind="image", name="figure", data=events_file)
assert len(results.df.values) == 1
with patch("polyaxon.tracking.run.Run._log_has_events") as log_dashboard:
self.run.log_mpl_plotly_chart(name="figure", figure=figure, step=2)
assert log_dashboard.call_count == 1
assert plt.fignum_exists(figure.number) is False
self.event_logger.flush()
assert (
os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.CHART))
is False
)
assert (
os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.CHART))
is True
)
events_file = get_event_path(
self.run_path, kind=V1ArtifactKind.CHART, name="figure"
)
assert os.path.exists(events_file) is True
results = V1Events.read(kind="image", name="figure", data=events_file)
assert len(results.df.values) == 2