Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
replace cairo.format with savefig.format in rcParams, apply to most b…
…ackends

replace some stray tabs with spaces
  • Loading branch information
mspacek committed Jun 3, 2012
commit e58fa078183e7734396de106d5cc046adc46e5a2
25 changes: 12 additions & 13 deletions doc/pyplots/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ backend : Agg
# circles. See
# http://matplotlib.sourceforge.net/matplotlib.patches.html for more
# information on patch properties
#patch.linewidth : 1.0 # edge width in points
#patch.facecolor : blue
#patch.edgecolor : black
#patch.antialiased : True # render patches in antialised (no jaggies)
#patch.linewidth : 1.0 # edge width in points
#patch.facecolor : blue
#patch.edgecolor : black
#patch.antialiased : True # render patches in antialised (no jaggies)

### FONT
#
Expand Down Expand Up @@ -152,11 +152,11 @@ backend : Agg
#text.markup : 'plain' # Affects how text, such as titles and labels, are
# interpreted by default.
# 'plain': As plain, unformatted text
# 'tex': As TeX-like text. Text between $'s will be
# formatted as a TeX math expression.
# This setting has no effect when text.usetex is True.
# In that case, all text will be sent to TeX for
# processing.
# 'tex': As TeX-like text. Text between $'s will be
# formatted as a TeX math expression.
# This setting has no effect when text.usetex is True.
# In that case, all text will be sent to TeX for
# processing.

# The following settings allow you to select the fonts in math mode.
# They map from a TeX font name to a fontconfig font pattern.
Expand All @@ -170,8 +170,8 @@ backend : Agg
#mathtext.fontset : cm # Should be 'cm' (Computer Modern), 'stix',
# 'stixsans' or 'custom'
#mathtext.fallback_to_cm : True # When True, use symbols from the Computer Modern
# fonts when a symbol can not be found in one of
# the custom math fonts.
# fonts when a symbol can not be found in one of
# the custom math fonts.

### AXES
# default face and edge color, default tick sizes,
Expand Down Expand Up @@ -266,8 +266,7 @@ figure.figsize : 6, 4 # figure size in inches
#savefig.dpi : 100 # figure dots per inch
#savefig.facecolor : white # figure facecolor when saving
#savefig.edgecolor : white # figure edgecolor when saving

#cairo.format : png # png, ps, pdf, svg
#savefig.format : png # png, ps, pdf, svg
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure savefig.format falls in the same class of things as dpi, facecolor, edgecolor which applies to the plt.savefig function (I think) whereas format would only apply to GUI save dialogues.

Obviously, this is also breaking backwards compatibility, which at the best should be noted in the doc/api/api_changes.rst.

Would any devs care to suggest appropriate actions (if any) for these issues.


# tk backend params
#tk.window_focus : False # Maintain shell focus for TkAgg
Expand Down
8 changes: 2 additions & 6 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ def byte2str(b): return b

from matplotlib.rcsetup import (defaultParams,
validate_backend,
validate_toolbar,
validate_cairo_format)
validate_toolbar)

major, minor1, minor2, s, tmp = sys.version_info
_python24 = (major == 2 and minor1 >= 4) or major >= 3
Expand Down Expand Up @@ -943,10 +942,7 @@ def use(arg, warn=True):
be_parts = arg.split('.')
name = validate_backend(be_parts[0])
if len(be_parts) > 1:
if name == 'cairo':
rcParams['cairo.format'] = validate_cairo_format(be_parts[1])
else:
raise ValueError('Only cairo backend has a format option')
raise ValueError('FIXME: Not sure what to do here')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only just learnt of the matplotlib.use('cairo.pdf') style syntax, and IMHO its pretty ugly.

One of the important things that this is doing is limiting the default format in a Cairo backend to 'png', 'ps', 'pdf', 'svg' (I notice that this doesn't include the Cairo backend supported "svgz"), but, as far as I can see, this validation is handled automatically by the rcParams dictionary.

In which case, other than a few fewer keystrokes, I see no benefit to:

matplotlib.use('cairo.pdf')

over

matplotlib.use('cairo')
rcParams['savefig.format'] = 'pdf'

Therefore I propose that the Cairo backend be brought back into line with the other backends by removing the cariro.<format> syntax in matpltolib.use, by exposing a get_supported_filetypes on the Cairo backend, and by validating the default format at savefig time (as has been proposed for all backends further down this pull request).

rcParams['backend'] = name

def get_backend():
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',


def get_default_filetype(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my earlier comment, this method could really do with a docstring (whilst your there, get_supported_filetypes() and get_supported_filetypes_grouped() should get a docstring too, if possible).

raise NotImplementedError
return rcParams['savefig.format']

def set_window_title(self, title):
"""
Expand Down
3 changes: 0 additions & 3 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,6 @@ def buffer_rgba(self):
'debug-annoying')
return self.renderer.buffer_rgba()

def get_default_filetype(self):
return 'png'

def print_raw(self, filename_or_obj, *args, **kwargs):
FigureCanvasAgg.draw(self)
renderer = self.get_renderer()
Expand Down
4 changes: 0 additions & 4 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
from matplotlib.path import Path
from matplotlib.transforms import Bbox, Affine2D
from matplotlib.font_manager import ttfFontProperty
from matplotlib import rcParams

_debug = False
#_debug = True
Expand Down Expand Up @@ -430,9 +429,6 @@ def print_svg(self, fobj, *args, **kwargs):
def print_svgz(self, fobj, *args, **kwargs):
return self._save(fobj, 'svgz', *args, **kwargs)

def get_default_filetype(self):
return rcParams['cairo.format']

def _save (self, fo, format, **kwargs):
# save PDF/PS/SVG
orientation = kwargs.get('orientation', 'portrait')
Expand Down
4 changes: 0 additions & 4 deletions lib/matplotlib/backends/backend_gdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def fn_name(): return sys._getframe(1).f_code.co_name
from matplotlib.transforms import Affine2D
from matplotlib.backends._backend_gdk import pixbuf_get_pixels_array


backend_version = "%d.%d.%d" % gtk.pygtk_version
_debug = False

Expand Down Expand Up @@ -465,6 +464,3 @@ def _print_image(self, filename, format, *args, **kwargs):
0, 0, 0, 0, width, height)

pixbuf.save(filename, format)

def get_default_filetype(self):
return 'png'
12 changes: 5 additions & 7 deletions lib/matplotlib/backends/backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
from matplotlib import markers
from matplotlib import cbook
from matplotlib import verbose
from matplotlib import rcParams

backend_version = "%d.%d.%d" % gtk.pygtk_version

Expand Down Expand Up @@ -474,9 +475,6 @@ def save_callback(buf, data=None):
else:
raise ValueError("filename must be a path or a file-like object")

def get_default_filetype(self):
return 'png'

def new_timer(self, *args, **kwargs):
"""
Creates a new backend-specific subclass of :class:`backend_bases.Timer`.
Expand Down Expand Up @@ -606,9 +604,9 @@ def full_screen_toggle (self):
def _get_toolbar(self, canvas):
# must be inited after the window, drawingArea and figure
# attrs are set
if matplotlib.rcParams['toolbar'] == 'classic':
if rcParams['toolbar'] == 'classic':
toolbar = NavigationToolbar (canvas, self.window)
elif matplotlib.rcParams['toolbar'] == 'toolbar2':
elif rcParams['toolbar'] == 'toolbar2':
toolbar = NavigationToolbar2GTK (canvas, self.window)
else:
toolbar = None
Expand Down Expand Up @@ -698,7 +696,7 @@ def _init_toolbar(self):


def _init_toolbar2_4(self):
basedir = os.path.join(matplotlib.rcParams['datapath'],'images')
basedir = os.path.join(rcParams['datapath'],'images')
if not _new_tooltip_api:
self.tooltips = gtk.Tooltips()

Expand Down Expand Up @@ -1257,7 +1255,7 @@ def on_dialog_lineprops_cancelbutton_clicked(self, button):
icon_filename = 'matplotlib.png'
else:
icon_filename = 'matplotlib.svg'
window_icon = os.path.join(matplotlib.rcParams['datapath'], 'images', icon_filename)
window_icon = os.path.join(rcParams['datapath'], 'images', icon_filename)
except:
window_icon = None
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1])
Expand Down
12 changes: 5 additions & 7 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
from matplotlib import lines
from matplotlib import cbook
from matplotlib import verbose
from matplotlib import rcParams

backend_version = "%s.%s.%s" % (Gtk.get_major_version(), Gtk.get_micro_version(), Gtk.get_minor_version())

Expand Down Expand Up @@ -303,9 +304,6 @@ def idle_draw(*args):
if self._idle_draw_id == 0:
self._idle_draw_id = GObject.idle_add(idle_draw)

def get_default_filetype(self):
return 'png'

def new_timer(self, *args, **kwargs):
"""
Creates a new backend-specific subclass of :class:`backend_bases.Timer`.
Expand Down Expand Up @@ -435,9 +433,9 @@ def full_screen_toggle (self):
def _get_toolbar(self, canvas):
# must be inited after the window, drawingArea and figure
# attrs are set
if matplotlib.rcParams['toolbar'] == 'classic':
if rcParams['toolbar'] == 'classic':
toolbar = NavigationToolbar (canvas, self.window)
elif matplotlib.rcParams['toolbar'] == 'toolbar2':
elif rcParams['toolbar'] == 'toolbar2':
toolbar = NavigationToolbar2GTK3 (canvas, self.window)
else:
toolbar = None
Expand Down Expand Up @@ -512,7 +510,7 @@ def draw_rubberband(self, event, x0, y0, x1, y1):

def _init_toolbar(self):
self.set_style(Gtk.ToolbarStyle.ICONS)
basedir = os.path.join(matplotlib.rcParams['datapath'],'images')
basedir = os.path.join(rcParams['datapath'],'images')

for text, tooltip_text, image_file, callback in self.toolitems:
if text is None:
Expand Down Expand Up @@ -1055,7 +1053,7 @@ def on_dialog_lineprops_cancelbutton_clicked(self, button):
icon_filename = 'matplotlib.png'
else:
icon_filename = 'matplotlib.svg'
window_icon = os.path.join(matplotlib.rcParams['datapath'], 'images', icon_filename)
window_icon = os.path.join(rcParams['datapath'], 'images', icon_filename)
except:
window_icon = None
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1])
Expand Down
15 changes: 6 additions & 9 deletions lib/matplotlib/backends/backend_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from matplotlib.path import Path
from matplotlib.mathtext import MathTextParser
from matplotlib.colors import colorConverter

from matplotlib import rcParams

from matplotlib.widgets import SubplotTool

Expand Down Expand Up @@ -225,7 +225,7 @@ def draw_if_interactive():
it will be redrawn as soon as the event loop resumes via PyOS_InputHook.
This function should be called after each draw event, even if
matplotlib is not running interactively.
"""
"""
if matplotlib.is_interactive():
figManager = Gcf.get_active()
if figManager is not None:
Expand Down Expand Up @@ -330,9 +330,6 @@ def print_tiff(self, filename, *args, **kwargs):
def print_gif(self, filename, *args, **kwargs):
self._print_bitmap(filename, *args, **kwargs)

def get_default_filetype(self):
return 'png'

def new_timer(self, *args, **kwargs):
"""
Creates a new backend-specific subclass of :class:`backend_bases.Timer`.
Expand All @@ -357,9 +354,9 @@ def __init__(self, canvas, num):
FigureManagerBase.__init__(self, canvas, num)
title = "Figure %d" % num
_macosx.FigureManager.__init__(self, canvas, title)
if matplotlib.rcParams['toolbar']=='classic':
if rcParams['toolbar']=='classic':
self.toolbar = NavigationToolbarMac(canvas)
elif matplotlib.rcParams['toolbar']=='toolbar2':
elif rcParams['toolbar']=='toolbar2':
self.toolbar = NavigationToolbar2Mac(canvas)
else:
self.toolbar = None
Expand All @@ -384,7 +381,7 @@ class NavigationToolbarMac(_macosx.NavigationToolbar):

def __init__(self, canvas):
self.canvas = canvas
basedir = os.path.join(matplotlib.rcParams['datapath'], "images")
basedir = os.path.join(rcParams['datapath'], "images")
images = {}
for imagename in ("stock_left",
"stock_right",
Expand Down Expand Up @@ -453,7 +450,7 @@ def __init__(self, canvas):
NavigationToolbar2.__init__(self, canvas)

def _init_toolbar(self):
basedir = os.path.join(matplotlib.rcParams['datapath'], "images")
basedir = os.path.join(rcParams['datapath'], "images")
_macosx.NavigationToolbar2.__init__(self, basedir)

def draw_rubberband(self, event, x0, y0, x1, y1):
Expand Down
7 changes: 2 additions & 5 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,9 +1190,6 @@ def _print_image(self, filename, filetype, *args, **kwargs):
self.draw()
self.Refresh()

def get_default_filetype(self):
return 'png'

def _onPaint(self, evt):
"""
Called when wxPaintEvt is generated
Expand Down Expand Up @@ -1513,9 +1510,9 @@ def __init__(self, num, fig):
bind(self, wx.EVT_CLOSE, self._onClose)

def _get_toolbar(self, statbar):
if matplotlib.rcParams['toolbar']=='classic':
if rcParams['toolbar']=='classic':
toolbar = NavigationToolbarWx(self.canvas, True)
elif matplotlib.rcParams['toolbar']=='toolbar2':
elif rcParams['toolbar']=='toolbar2':
toolbar = NavigationToolbar2Wx(self.canvas)
toolbar.set_status_bar(statbar)
else:
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ def validate_font_properties(s):
'silent', 'helpful', 'debug', 'debug-annoying',
])

validate_cairo_format = ValidateInStrings('cairo_format',
['png', 'ps', 'pdf', 'svg'],
ignorecase=True)
validate_savefig_format = ValidateInStrings('savefig_format',
['png', 'ps', 'pdf', 'svg'],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this, as far as I can see, is that you cannot guarantee what filetypes are valid until you know what backend is being used, and you cannot know what backend is being used until runtime. Therefore, for many of the backends, it would make sense for get_default_filetype to do something like:

def get_default_filetype(self):
    default = rcParams['savefig.format']
    if default in self.get_supported_filetypes().keys():
        return default
    else:
        return 'png'

ignorecase=True)

validate_ps_papersize = ValidateInStrings('ps_papersize',[
'auto', 'letter', 'legal', 'ledger',
Expand Down Expand Up @@ -547,8 +547,8 @@ def __call__(self, s):
'savefig.edgecolor' : ['w', validate_color], # edgecolor; white
'savefig.orientation' : ['portrait', validate_orientation], # edgecolor; white
'savefig.extension' : ['auto', str], # what to add to extensionless filenames
'savefig.format' : ['png', validate_savefig_format],

'cairo.format' : ['png', validate_cairo_format],
'tk.window_focus' : [False, validate_bool], # Maintain shell focus for TkAgg
'tk.pythoninspect' : [False, validate_tkpythoninspect], # obsolete
'ps.papersize' : ['letter', validate_ps_papersize], # Set the papersize/type
Expand Down
7 changes: 3 additions & 4 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
#savefig.facecolor : white # figure facecolor when saving
#savefig.edgecolor : white # figure edgecolor when saving
#savefig.extension : auto # what extension to use for savefig('foo'), or 'auto'

#cairo.format : png # png, ps, pdf, svg
#savefig.format : png # png, ps, pdf, svg

# tk backend params
#tk.window_focus : False # Maintain shell focus for TkAgg
Expand Down Expand Up @@ -434,8 +433,8 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
# -1 implies let utility auto-determine
#animation.frame_format: 'png' # Controls frame format used by temp files
#animation.ffmpeg_path: 'ffmpeg' # Path to ffmpeg binary. Without full path
# $PATH is searched
# $PATH is searched
#animation.ffmpeg_args: '' # Additional arugments to pass to mencoder
#animation.mencoder_path: 'ffmpeg' # Path to mencoder binary. Without full path
# $PATH is searched
# $PATH is searched
#animation.mencoder_args: '' # Additional arugments to pass to mencoder