Bug while exporting a plot Item

801 views
Skip to first unread message

François Bocquet

unread,
Sep 9, 2013, 5:30:18 AM9/9/13
to pyqt...@googlegroups.com
Dear all,

I encountered a puzzling bug while exporting a plotItem. In the actual
window of the program, the displays curves are fine but if this very
plot is exported programmatically with:
exporter =
pyqtgraph.exporters.ImageExporter.ImageExporter(the_plot.plotItem)
exporter.parameters()['width'] = 1000
exporter.params['background'] = (0,0,0,0)
exporter.export(file_name+'.png')

one curve (blue circles) is displaced both in X and Y direction with
respect to the display (see attached Fit_refl.png).

Now if I save manually always the same plot, it's saved as displayed:
that is to say fine! See attached Fit.refl_manualSave_ubuntu.png.

This was observed with Ubuntu 12.04 LTS.
The worse is that it works fine with Windows7!

What information could I provide in order to get this bug to understanding?
I should probably mention that the X-vector of each curve are not the
same list.

Regards
Fran�ois
Fit_refl.png
Fit_refl_manualSave_ubuntu.png

Luke Campagnola

unread,
Sep 10, 2013, 12:55:06 AM9/10/13
to pyqt...@googlegroups.com
On Mon, Sep 9, 2013 at 5:30 AM, François Bocquet <bocq...@gmail.com> wrote:
I encountered a puzzling bug while exporting a plotItem. In the actual window of the program, the displays curves are fine but if this very plot is exported programmatically with:
            exporter = pyqtgraph.exporters.ImageExporter.ImageExporter(the_plot.plotItem)
            exporter.parameters()['width'] = 1000
            exporter.params['background'] = (0,0,0,0)
            exporter.export(file_name+'.png')

one curve (blue circles) is displaced both in X and Y direction with respect to the display (see attached Fit_refl.png).

Now if I save manually always the same plot, it's saved as displayed: that is to say fine! See attached Fit.refl_manualSave_ubuntu.png.

This was observed with Ubuntu 12.04 LTS.
The worse is that it works fine with Windows7!

That is indeed strange. The first thing I notice is that the scatter plot points occupy exactly the same pixel locations in both images, so apparently the scatter plot is not being informed that the view size has changed to 1000px during the export. However, I am not able to reproduce this with a simple plot+export test (on Ubuntu 13.04). The best thing you can provide is a short example that demonstrates the problem. If I can reproduce it on my end, I'll be happy to provide a fix.


Luke

 

François Bocquet

unread,
Sep 10, 2013, 8:09:53 AM9/10/13
to pyqt...@googlegroups.com
Dear Luke,

There you go. I usually just use this command:

$ pyuic4 expTestWin.ui -o expTestWin.py; python export_test.py

You are right, this bug is width-dependant.
I hope this helps.
I didn't try it on windows 7. I can if you want.

Best
Fran�ois


On 09/10/2013 06:55 AM, Luke Campagnola wrote:
> On Mon, Sep 9, 2013 at 5:30 AM, Fran�ois Bocquet <bocq...@gmail.com
> <mailto:bocq...@gmail.com>> wrote:
>
> I encountered a puzzling bug while exporting a plotItem. In the
> actual window of the program, the displays curves are fine but if
> this very plot is exported programmatically with:
> exporter =
> pyqtgraph.exporters.__ImageExporter.ImageExporter(__the_plot.plotItem)
> exporter.parameters()['width'] = 1000
> exporter.params['background'] = (0,0,0,0)
> exporter.export(file_name+'.__png')
>
> one curve (blue circles) is displaced both in X and Y direction with
> respect to the display (see attached Fit_refl.png).
>
> Now if I save manually always the same plot, it's saved as
> displayed: that is to say fine! See attached
> Fit.refl_manualSave_ubuntu.__png.
>
> This was observed with Ubuntu 12.04 LTS.
> The worse is that it works fine with Windows7!
>
>
> That is indeed strange. The first thing I notice is that the scatter
> plot points occupy exactly the same pixel locations in both images, so
> apparently the scatter plot is not being informed that the view size has
> changed to 1000px during the export. However, I am not able to reproduce
> this with a simple plot+export test (on Ubuntu 13.04). The best thing
> you can provide is a short example that demonstrates the problem. If I
> can reproduce it on my end, I'll be happy to provide a fix.
>
>
> Luke
>
> --
> -- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe,
> send email to pyqtgraph+...@googlegroups.com ]
> ---
> You received this message because you are subscribed to the Google
> Groups "pyqtgraph" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pyqtgraph+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
expTestWin.py
export_test.py
expTestWin.ui

Guillaume Poulin

unread,
Sep 10, 2013, 10:23:22 AM9/10/13
to pyqt...@googlegroups.com
I'm not able to reproduce the exact same bug using your example but I have something similar. The line plot and the scatter plot are always at the right place but the axis title are at the wrong places. However the problem go away when exported manually.


Le mardi 10 septembre 2013 20:09:53 UTC+8, François Bocquet a écrit :
Dear Luke,

There you go. I usually just use this command:

$ pyuic4 expTestWin.ui -o expTestWin.py; python export_test.py

You are right, this bug is width-dependant.
I hope this helps.
I didn't try it on windows 7. I can if you want.

Best
Fran�ois


On 09/10/2013 06:55 AM, Luke Campagnola wrote:
> On Mon, Sep 9, 2013 at 5:30 AM, Fran�ois Bocquet <bocq...@gmail.com
test_1000.png
test_1000_manual.png

Richard Smith

unread,
Sep 18, 2013, 12:08:15 PM9/18/13
to pyqt...@googlegroups.com


I encountered a puzzling bug while exporting a plotItem. In the actual
window of the program, the displays curves are fine but if this very
plot is exported programmatically with:
             exporter =
pyqtgraph.exporters.ImageExporter.ImageExporter(the_plot.plotItem)
             exporter.parameters()['width'] = 1000
             exporter.params['background'] = (0,0,0,0)
             exporter.export(file_name+'.png')

Can you post up a little more code on how you acquire a reference to "the_plot.plotItem"?  I want to save my entire window (2 plots) and I either seem to get 

AttributeError: 'GraphicsWindow' object has no attribute 'mapRectToDevice'

or 
 
ValueError: Buffer size too small (0 instead of at least 1 bytes)

Depending on what I try to pass to the exporter.

Thanks.

Luke Campagnola

unread,
Sep 18, 2013, 12:45:47 PM9/18/13
to pyqt...@googlegroups.com
On Wed, Sep 18, 2013 at 12:08 PM, Richard Smith <smit...@gmail.com> wrote:


I encountered a puzzling bug while exporting a plotItem. In the actual
window of the program, the displays curves are fine but if this very
plot is exported programmatically with:
             exporter =
pyqtgraph.exporters.ImageExporter.ImageExporter(the_plot.plotItem)
             exporter.parameters()['width'] = 1000
             exporter.params['background'] = (0,0,0,0)
             exporter.export(file_name+'.png')

Can you post up a little more code on how you acquire a reference to "the_plot.plotItem"?  I want to save my entire window (2 plots) and I either seem to get 

AttributeError: 'GraphicsWindow' object has no attribute 'mapRectToDevice'


The exporters require either a GraphicsItem or a GraphicsScene to export, so graphics_window.scene() should work, or you can pick a specific item that you have added to the scene.


Luke

 

Richard Smith

unread,
Sep 18, 2013, 12:57:28 PM9/18/13
to pyqt...@googlegroups.com


Can you post up a little more code on how you acquire a reference to "the_plot.plotItem"?  I want to save my entire window (2 plots) and I either seem to get 

AttributeError: 'GraphicsWindow' object has no attribute 'mapRectToDevice'


The exporters require either a GraphicsItem or a GraphicsScene to export, so graphics_window.scene() should work, or you can pick a specific item that you have added to the scene.

Thanks that's closer but using my the code in the other post if I pass in win.scene() I get output but both of my plots have been merged on top of each other.
 
Reply all
Reply to author
Forward
0 new messages