Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Low quality PDF when exporting plot with 200.000 data points

Subject: Low quality PDF when exporting plot with 200.000 data points

From: Casper

Date: 14 Apr, 2012 16:19:12

Message: 1 of 5

As the topic states:
I plot the correlation of two vectors, each of dimension 200.000 x 1, which (naturally) gives a lot of data points. Now when I export the figure (using print) the quality of the resulting pdf is quite... poor. However, reducing the number of data points severely increases the quality so it has to be a resolution problem.

Using '-r500' as an example of changing the resolution and up, I dont see any big improvement in the quality, which is really irritating. I have tried increasing '-r' up to 1400 but it doesnt seem to do a whole lot for the overall quality.

Anyone has a solution?

Subject: Low quality PDF when exporting plot with 200.000 data points

From: Roger Stafford

Date: 14 Apr, 2012 17:55:14

Message: 2 of 5

"Casper " <casper.ptrsn@gmail.com> wrote in message <jmc820$map$1@newscl01ah.mathworks.com>...
> As the topic states:
> I plot the correlation of two vectors, each of dimension 200.000 x 1, which (naturally) gives a lot of data points. Now when I export the figure (using print) the quality of the resulting pdf is quite... poor. However, reducing the number of data points severely increases the quality so it has to be a resolution problem.
>
> Using '-r500' as an example of changing the resolution and up, I dont see any big improvement in the quality, which is really irritating. I have tried increasing '-r' up to 1400 but it doesnt seem to do a whole lot for the overall quality.
>
> Anyone has a solution?
- - - - - - - - - -
  It is inherent in statistics that finding the joint distribution of two random variables using only sampling requires a very large number of samples to obtain a decent distribution function. In your example suppose you assume that you need a resolution of, say, a hundred value intervals for each random variable. That makes a total of in effect ten thousand two-dimensional boxes in which you must take sampling counts, and that in turn for your two hundred thousand samples means an average of a meager twenty samples per box. In the absence of any other information about these distributions, such as smoothness, bounds on derivatives, etc., having only twenty is bound to give poor accuracy. As I say, all this is inherent in the very nature of statistics itself. Matlab can't help you with this. The obvious solution is to either take advantage of other known properties of such
distributions or else use far higher numbers of samples than you are doing. With multivariate distributions with larger numbers of variables, this problem becomes even more severe, as you can imagine.

Roger Stafford

Subject: Low quality PDF when exporting plot with 200.000 data points

From: matt dash

Date: 14 Apr, 2012 20:45:13

Message: 3 of 5

"Casper " <casper.ptrsn@gmail.com> wrote in message <jmc820$map$1@newscl01ah.mathworks.com>...
> As the topic states:
> I plot the correlation of two vectors, each of dimension 200.000 x 1, which (naturally) gives a lot of data points. Now when I export the figure (using print) the quality of the resulting pdf is quite... poor. However, reducing the number of data points severely increases the quality so it has to be a resolution problem.
>
> Using '-r500' as an example of changing the resolution and up, I dont see any big improvement in the quality, which is really irritating. I have tried increasing '-r' up to 1400 but it doesnt seem to do a whole lot for the overall quality.
>
> Anyone has a solution?

I believe PDFs don't use resolution like the bitmap formats do. Increasing -r on pdf only uses more decimal places to make things more precise. If you're seeing poor quality, it is because you're exporting with the renderer set to zbuffer or opengl so it's exporting a low res bitmap into a pdf file. Specify painters when you call print (might also need to set the figure renderer to painters) and it will export a nice pdf. Though with that much data it might be a very large file.

The reason fewer points increases the quality is that when you have too many points the renderer automatically switches to opengl unless you explicitly set it to painters.

Subject: Low quality PDF when exporting plot with 200.000 data points

From: Casper

Date: 15 Apr, 2012 00:40:33

Message: 4 of 5

"matt dash" wrote in message <jmcnkp$m2v$1@newscl01ah.mathworks.com>...
> "Casper " <casper.ptrsn@gmail.com> wrote in message <jmc820$map$1@newscl01ah.mathworks.com>...
> > As the topic states:
> > I plot the correlation of two vectors, each of dimension 200.000 x 1, which (naturally) gives a lot of data points. Now when I export the figure (using print) the quality of the resulting pdf is quite... poor. However, reducing the number of data points severely increases the quality so it has to be a resolution problem.
> >
> > Using '-r500' as an example of changing the resolution and up, I dont see any big improvement in the quality, which is really irritating. I have tried increasing '-r' up to 1400 but it doesnt seem to do a whole lot for the overall quality.
> >
> > Anyone has a solution?
>
> I believe PDFs don't use resolution like the bitmap formats do. Increasing -r on pdf only uses more decimal places to make things more precise. If you're seeing poor quality, it is because you're exporting with the renderer set to zbuffer or opengl so it's exporting a low res bitmap into a pdf file. Specify painters when you call print (might also need to set the figure renderer to painters) and it will export a nice pdf. Though with that much data it might be a very large file.
>
> The reason fewer points increases the quality is that when you have too many points the renderer automatically switches to opengl unless you explicitly set it to painters.

That makes sense, though I not quite sure it is entirely correct. Painters is the default setting that I was using up until I ran into this issue, and the quality is poor. It does seem somewhat contradictory that fewer points opts for a change in the renderer. Shouldnt that scale when you add more points i.e. retain using opengl as the renderer for many data points?

Subject: Low quality PDF when exporting plot with 200.000 data points

From: matt dash

Date: 15 Apr, 2012 14:49:09

Message: 5 of 5

"Casper " <casper.ptrsn@gmail.com> wrote in message <jmd5e1$eea$1@newscl01ah.mathworks.com>...
> "matt dash" wrote in message <jmcnkp$m2v$1@newscl01ah.mathworks.com>...
> > "Casper " <casper.ptrsn@gmail.com> wrote in message <jmc820$map$1@newscl01ah.mathworks.com>...
> > > As the topic states:
> > > I plot the correlation of two vectors, each of dimension 200.000 x 1, which (naturally) gives a lot of data points. Now when I export the figure (using print) the quality of the resulting pdf is quite... poor. However, reducing the number of data points severely increases the quality so it has to be a resolution problem.
> > >
> > > Using '-r500' as an example of changing the resolution and up, I dont see any big improvement in the quality, which is really irritating. I have tried increasing '-r' up to 1400 but it doesnt seem to do a whole lot for the overall quality.
> > >
> > > Anyone has a solution?
> >
> > I believe PDFs don't use resolution like the bitmap formats do. Increasing -r on pdf only uses more decimal places to make things more precise. If you're seeing poor quality, it is because you're exporting with the renderer set to zbuffer or opengl so it's exporting a low res bitmap into a pdf file. Specify painters when you call print (might also need to set the figure renderer to painters) and it will export a nice pdf. Though with that much data it might be a very large file.
> >
> > The reason fewer points increases the quality is that when you have too many points the renderer automatically switches to opengl unless you explicitly set it to painters.
>
> That makes sense, though I not quite sure it is entirely correct. Painters is the default setting that I was using up until I ran into this issue, and the quality is poor. It does seem somewhat contradictory that fewer points opts for a change in the renderer. Shouldnt that scale when you add more points i.e. retain using opengl as the renderer for many data points?

Read my last paragraph. Using MORE points changes the renderer to opengl. opengl = low quality, painters = high quality.

Here try this:
data=rand(200000,2);
plot(data(:,1),data(:,2),'b.');
print(gcf,'test1.pdf','-dpdf','-painters','-r300'); %<-- a high quality pdf
print(gcf,'test2.pdf','-dpdf','-opengl','-r300'); %<-- a low quality pdf

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us