X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Fplot.py;h=b301e307aa30514d8865ba9ac7423c5b7170a8fa;hb=506ce3431f3a3b230c5976c192b8144668e9176a;hp=d33012314db2dae46713ca10c2389063acac58ef;hpb=3a61b951df61f4175bcf61700454ed978b63b2ef;p=sage.d.git diff --git a/mjo/plot.py b/mjo/plot.py index d330123..b301e30 100644 --- a/mjo/plot.py +++ b/mjo/plot.py @@ -1,32 +1,48 @@ +""" +Plotting helpers. + + * We set the default tick_formatter to 'latex'. + + * We replace the plot() function with our own version that sets some + default legend options. + +""" + from sage.all import * -# Save the default so that we can call it within mjo_plot. +# Graphics.SHOW_OPTIONS contains the default options that will be +# passed to show(). It already handles merging the user-specified +# options, so we just tap into that power. +show_opts = sage.plot.graphics.Graphics.SHOW_OPTIONS +show_opts['tick_formatter'] = 'latex' + +# Save the default plot() function so that we can call it within +# mjo_plot and not die of recursion. 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' } - - legend_opts = { 'back_color': 'white', - 'shadow': True } - - # 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) - p.set_legend_options(**legend_opts) + default_legend_opts = { 'back_color': 'white', + 'shadow': True } + + # Create an empty plot using the default options. + p = Graphics() + p.set_legend_options(**default_legend_opts) + + # After trac #12936, this should propagate those options. + p += sage_plot(*args, **kwargs) + return p -# Replace both the global `plot` and the one in the module. I am + +# 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 plot = mjo_plot +sage.plot.plot.plot = mjo_plot +sage.plot.all.plot = mjo_plot