Skip to content
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

Cairo Backend: print_surface #1245

Closed
chdemars opened this issue Sep 13, 2012 · 5 comments
Closed

Cairo Backend: print_surface #1245

chdemars opened this issue Sep 13, 2012 · 5 comments

Comments

@chdemars
Copy link

In order to get matplotlib and mapnik to play nicely together, I had to alter backend_cairo.py by adding the following to the FigureCanvasCairo class:

def print_surface(self, fobj, *args, **kwargs):
    dpi = 72
    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)

Now I am a happy cartographer: I have maps and graphs on the same page all driven by a postgis database. Others might find this addition just as useful.

To use, just call:
mycanvas.print_surface(my_cairo_surface)

To move the location that the chart is printedl:
my_cairo_surface.set_device_offset(x,y)
mycanvas.print_surface(my_cairo_surface)

Cheers,
--Christopher

@pelson
Copy link
Member

pelson commented Sep 14, 2012

Hey @chdemars . Thanks for this, I'm not sure who our resident cairo expert is, but I expect somebody will be able to pick this up and create a PR from it (if that somebody were you, that would be even better).

Out of interest, will you be writing up the process of integrating the mpl and Mapnik somewhere? I would live to read it!

@chdemars
Copy link
Author

I initiated a pull request on the topic. I also have created an example
script to show how to use mapnik and matplotlib together. I'm not sure
where I should submit it and it's associated data.

--Christopher

On Fri, Sep 14, 2012 at 2:07 AM, Phil Elson notifications@github.comwrote:

Hey @chdemars https://github.com/chdemars . Thanks for this, I'm not
sure who our resident cairo expert is, but I expect somebody will be able
to pick this up and create a PR from it (if that somebody were you, that
would be even better).

Out of interest, will you be writing up the process of integrating the mpl
and Mapnik somewhere? I would live to read it!


Reply to this email directly or view it on GitHubhttps://github.com//issues/1245#issuecomment-8555558.

@pelson
Copy link
Member

pelson commented Sep 17, 2012

PR: #1245

@dmcdougall
Copy link
Member

@pelson The PR is #1254.

@tacaswell
Copy link
Member

The PR for this has (edit by @pelson: not) been merged. @chdemars If this isn't implemented please re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants