Results 1 to 5 of 5

Thread: Saving pure plot data to image file

  1. #1
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Saving pure plot data to image file

    Hi,
    I have an application which displays a stack of QwtPlotSpectrograms that I’d like to export as PNG or other image formats. Since the underlying data is really raster based, I’d be fine with going through the data array myself and setting each and every pixel directly to a PNG QImage. There should not be any stretching or resizing be necessary.

    The problem is, that it is getting more and more complicated the more (semi-transparent) spectrograms I use, just because then I will have to recalculate the colour and all the stuff that has already been done by the QwtPlot.

    I’ve read through “Saving qwt plot as image” and adapted one of the solutions
    Qt Code:
    1. QImage image(600, 600, QImage::Format_ARGB32);
    2. pixmap.fill(Qt::white);
    3.  
    4. int options = QwtPlotPrintFilter::PrintAll;
    5. options &= ~QwtPlotPrintFilter::PrintBackground;
    6. options &= ~QwtPlotPrintFilter::PrintFrameWithScales;
    7. options &= ~QwtPlotPrintFilter::PrintMargin;
    8. options &= ~QwtPlotPrintFilter::PrintTitle;
    9. options &= ~QwtPlotPrintFilter::PrintLegend ;
    10. options &= ~QwtPlotPrintFilter::PrintGrid;
    11. filter.setOptions(options);
    12.  
    13. qwt_plot->print(pixmap, image);
    To copy to clipboard, switch view to plain text mode 

    However, I find no way to disable the axes or the colour bar. What do I need to do in order to have the plain plot without any surrounding extras? (See the attached file.)
    In the documentation it says that QwtPlotPrintFilter is outdated, so I guess there should be a better way to do this.

    Another thing that you can see in the attached image is, that the x and y axes go from 0 to 70, so there is some unfilled space between 64 an 70 on each coordinate. How can I tell QwtPlot that these axes should really only go to 64? (Edit note: I think, I’ve been able to fix this subproblem with a simple setAxisScale)

    (And, while I’m at it: Can one have two colour bars next to each other? Looking at the documentation, I feel this is not possible but maybe it is…?)

    Many thanks.
    Attached Images Attached Images
    Last edited by Debilski; 2nd April 2009 at 23:21. Reason: One third of the problems already solved.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Saving pure plot data to image file

    However, I find no way to disable the axes or the colour bar.
    plot->enableAxis(..., false); ( The color bar is part of the axis widget ).
    You can disable the axes before printing and re-enable them if you want to hide them for printing only.
    (And, while I’m at it: Can one have two colour bars next to each other? Looking at the documentation, I feel this is not possible but maybe it is…?)
    You can put other QwtScaleWidgets below or beside the plot widget ( using a QBoxLayout ). But of course you need to write additional layout code to include it to your print.

    HTH,
    Uwe

    Uwe

  3. #3
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Saving pure plot data to image file

    Quote Originally Posted by Uwe View Post
    plot->enableAxis(..., false); ( The color bar is part of the axis widget ).
    You can disable the axes before printing and re-enable them if you want to hide them for printing only.
    Thanks, that did work. However, it leaves a border of three or so pixels around the image. I tried with setMargin(0) and setCanvasLineWidth(0) but that did not help. If it is always three pixels, I could live with it, though. Any suggestions?

  4. #4
    Join Date
    Mar 2009
    Posts
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving pure plot data to image file

    Quote Originally Posted by Debilski View Post
    Thanks, that did work. However, it leaves a border of three or so pixels around the image. I tried with setMargin(0) and setCanvasLineWidth(0) but that did not help. If it is always three pixels, I could live with it, though. Any suggestions?
    Hi,
    Did you look at this:
    http://www.qtcentre.org/forum/f-qwt-...ata-19641.html
    Maybe this fits your situation.


    Hüseyin

  5. #5
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Saving pure plot data to image file

    Quote Originally Posted by huseyinkozan View Post
    Hi,
    Did you look at this:
    http://www.qtcentre.org/forum/f-qwt-...ata-19641.html
    Maybe this fits your situation.
    Thank you very much. Using setCanvasMargin() I was able to solve this problem.

Similar Threads

  1. Replies: 12
    Last Post: 31st October 2010, 18:08
  2. Replies: 2
    Last Post: 29th September 2008, 01:08
  3. Problem saving a plot
    By kalos80 in forum Qwt
    Replies: 2
    Last Post: 10th July 2008, 09:31
  4. data is not appending to the file
    By sudheer in forum Qt Tools
    Replies: 2
    Last Post: 3rd April 2008, 13:39
  5. FSWriteFork in MAC OS to write data to a file.
    By vishal.chauhan in forum General Programming
    Replies: 5
    Last Post: 2nd July 2007, 07:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.