Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6091461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:19:50+00:00 2026-05-23T12:19:50+00:00

I have a matplotlib figure inside of a wxmpl panel, and am trying to

  • 0

I have a matplotlib figure inside of a wxmpl panel, and am trying to print it to a Postscript file. The best I can get is a blank file – by ‘blank’ I don’t mean empty, but rather a .ps file with headers and whatnot but displays as just a blank page.

The code to print is:

printer = self.GetPrinter() # wxmpl.FigurePrinter
fig = self.get_figure() # matplotlib.figure.Figure
printData = wx.PrintData(printer.getPrintData())
printer.printFigure(fig, "Plot")
self.printer.setPrintData(printData) # reset print data (avoid segfaults)

I took a look into the wxmpl code and found that OnPrintPage is never called, so I tried adding a call to that via wxmpl.FigurePrintout.OnBeginDocument. Then OnPrintPage gets to this line:

self.GetDC().DrawBitmap(image.ConvertToBitmap(), wM_Dx, hM_Dx, False)

and throws an error:

wx._core.PyAssertionError
C++ assertion "wxAssertFailure" failed in ../src/generic/dcpsg.cpp(2238): invalid postscript dc

Google led me to this email string, and accordingly I tried replacing the above line with:

dc = self.GetDC()
dc.StartDoc("printing stuff")
dc.StartPage()
dc.BeginDrawing()
dc.DrawBitmap(image.ConvertToBitmap(), wM_Dx, hM_Dx, False)
dc.EndDrawing()
dc.EndPage()
dc.EndDoc()

That got rid of the error — but after all that it’s still just printing blank files as before.

Another note, simply saving the plot as Postscript works fine – it uses a different backend (FigureCanvasWxAgg instead of RendererAgg – so maybe the problem is in matplotlib instead of wxmpl/wxPython?). However, I need to print this to an actual printer as well, so special-casing for .ps files isn’t really a viable solution.

Running Linux
wxmpl version 1.2.9
wxPython version 2.6.4.0
matplotlib version 0.84 (yes, I know it’s horribly outdated, but that’s what I have to work with for now)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:19:51+00:00Added an answer on May 23, 2026 at 12:19 pm

    The problem was that wxmpl had no call to HasPage — the entirety of the changes above didn’t matter, after all. Adding in this code in class FigurePrintout fixed the issue with not printing:

    def HasPage(self, page):
        return page <= 1
    

    Yep… two lines. Based on the documentation for the wxPython printing framework, the default is return page == 1, but wxmpl returns 0 as the first page in it’s override of GetPageInfo. So the printer didn’t think it had a page to print.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a matplotlib figure that will have multiple horizontal boxplots
I have a wxPython application which contains a matplotlib panel (courtesy of wxmpl, though
I have a matplotlib figure on a canvas on a wxpython panel. My application
I have a class that has an output() method which returns a matplotlib Figure
Say that I have two figures in matplotlib, with one plot per figure: import
I have a matplotlib figure that I want to be able to switch between
I have a page with multiple Matplotlib figures embedded. The figures get inserted/manipulated via
Is there a way to save a Matplotlib figure such that it can be
I'm trying to create a Matplotlib animation of my paw data, where you can
I have used Matplotlib to plot lines on a figure. Now I would now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.