-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backend_cairo.py -- added print_surface method #1254
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -435,6 +435,16 @@ def print_svg(self, fobj, *args, **kwargs): | |
|
||
def print_svgz(self, fobj, *args, **kwargs): | ||
return self._save(fobj, 'svgz', *args, **kwargs) | ||
|
||
def print_surface(self, fobj, *args, **kwargs): | ||
dpi = 72 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this hard-coding intentional? Is there a reason is doesn't take the default dpi from rcParams? Edit: Should it take the default from rcParams? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason that this is hard coded is because I aped the _save method As far as naming schemes goes, I'm not wedded to anything. I think I also have a very basic example of using this method to mix matplotlib and --Christopher On Thu, Sep 20, 2012 at 8:50 AM, Damon McDougall
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chdemars, no, please do not put all that in examples. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chdemars : Do you keep a blog? I think writing an article about matplotlib & mapnik would be a massive hit. If not, you could always create a small git repo with the contents, maybe even use github's free hosting... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
self.figure.dpi = dpi | ||
w_in, h_in = self.figure.get_size_inches() | ||
width_pt, height_pt = w_in * dpi, h_in * dpi | ||
renderer = RendererCairo(self.figure.dpi) | ||
renderer.set_width_height(width_pt, height_pt) | ||
renderer.set_ctx_from_surface(fobj) | ||
self.figure.draw(renderer) | ||
|
||
def _save (self, fo, format, **kwargs): | ||
# save PDF/PS/SVG | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other methods, as far as I can tell, are named
print_[filetype]
. Since 'surface' is not a filetype, perhaps this function should be called something else? Perhaps this is really nit-picky, though. I have also just realised it doesn't actually save a file, it merely renders it to a canvas. The otherprint_[filetype]
methods write a physical file to disk. Perhapsrender_to_canvas
would be more appropriate?Maybe some of the other devs could chime in here.
Edit: Perhaps also a docstring describing what
fobj
is and what are vaid args and kwargs. On further inspection, it doesn't look like the args and kwargs get passed anywhere. Is this intentional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for seeing this late. I think I agree with @dmcdougall here, let's call it "print_to_surface", and the
fobj
argument name should besurface
(or whatever the convention is in cairo), since it is definitely not a file object.