from sage.all import * # Save the default so that we can call it within mjo_plot. sage_plot = plot def mjo_plot(*args, **kwargs): """ Replacement for the default plot function. - Use the 'latex' tick formatter. - If there's a legend, set the background color to 'white' and give it a drop shadow. """ plot_opts = { 'tick_formatter': 'latex' } # Merge the user's plot options with mine. The ones given as # kwargs should override the defaults! plot_opts.update(kwargs) kwargs = plot_opts p = sage_plot(*args, **kwargs) # Merge the user's legend options with mine. The ones passed to us # should override the defaults! default_legend_opts = { 'back_color': 'white', 'shadow': True } default_legend_opts.update(p._Graphics__legend_opts) p._Graphics__legend_opts = default_legend_opts return p # Replace both the global `plot` and the ones in the modules. I am # unclear about why this is necessary, and don't care too much. sage.plot.plot.plot = mjo_plot sage.plot.all.plot = mjo_plot plot = mjo_plot