Hide Matplotlib Text during save -


i have 'paused' matplotlib text tell user graph paused. works great, not want word "paused" show when printing or saving.

figpausedtext = fig.text(0.5, 0.5,'paused', horizontalalignment='center',     verticalalignment='center',     transform=ax.transaxes,     alpha = 0.25,     size='x-large') 

what's best way hide paused text when saving/printing? i'm happy set_text('') if can bind save , print commands. particularly want make sure works when user clicks navigationtoolbar2tkagg toolbar.

something this:

figpausedtext = fig.text(...) def my_save(fig, * args, **kwargs):      figpausedtext.set_visible(false)      fig.savefig(*args, **kwargs)      figpausedtext.set_visible(true) 

if want clever, can monkey patch figure object:

import types  figpausedtext = fig.text(...) # make sure have copy of origanal savefig old_save = matplotlib.figure.figure.savefig # our new function hide , re-show text def my_save(fig, *args, **kwargs):      figpausedtext.set_visible(false)      ret = old_save(fig, *args, **kwargs)      figpausedtext.set_visible(true)      return ret # monkey patch instantiation   fig.savefig = types.methodtype(my_save, fig) 

or if need work through tool bar

import types  figpausedtext = fig.text(...) # make sure have copy of origanal print_figure old_print = fig.canvas.print_figure # bound function # if want right backend dependent # our new function hide , re-show text def my_save(canvas, *args, **kwargs):      figpausedtext.set_visible(false)      ret = old_print(*args, **kwargs) # saved bound function, don't need canvas      figpausedtext.set_visible(true)      return ret # monkey patch instantiation   fig.canvas.print_figure = types.methodtype(my_save, fig.canvas) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -