comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Plot scatter points with transparency
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Plot scatter points with transparency [message #94580] Fri, 14 July 2017 15:00 Go to next message
chengyuxi34 is currently offline  chengyuxi34
Messages: 4
Registered: January 2016
Junior Member
Is there a way to do transparent scatter plots? (Usually I use cgScatter2D.pro to do scatter plots)

I need to overlay a large number of scatter points in one plot, which consist of several groups. I want to assign different groups with different colors. The problems is they just tend to block each other due to the large number. Is a way to plot them with transparency or any other good solution?

Thanks,
Chengyu
Re: Plot scatter points with transparency [message #94581 is a reply to message #94580] Sat, 15 July 2017 09:24 Go to previous messageGo to next message
Nikola is currently offline  Nikola
Messages: 53
Registered: November 2009
Member
On Friday, July 14, 2017 at 11:00:31 PM UTC+1, ChengYu Xi wrote:
> Is there a way to do transparent scatter plots? (Usually I use cgScatter2D.pro to do scatter plots)
>
> I need to overlay a large number of scatter points in one plot, which consist of several groups. I want to assign different groups with different colors. The problems is they just tend to block each other due to the large number. Is a way to plot them with transparency or any other good solution?
>
> Thanks,
> Chengyu


A nice solution is to replace the central dense (all-black) cloud of points with a contour. An example is Fig.7 of
http://iopscience.iop.org/article/10.1086/590237/pdf

To make it, plot the contours of the 2D distribution/histogram, extract the data of the plotted contours using keywords path_xy = path_xy and /path_data_coords and then over-plot only those points that are out of the outermost contour line. I have a routine to do it, but I should prepare it a bit for sharing.
Re: Plot scatter points with transparency [message #94585 is a reply to message #94580] Sun, 16 July 2017 22:14 Go to previous messageGo to next message
Med Bennett is currently offline  Med Bennett
Messages: 109
Registered: April 1997
Senior Member
On Friday, July 14, 2017 at 4:00:31 PM UTC-6, ChengYu Xi wrote:
> Is there a way to do transparent scatter plots? (Usually I use cgScatter2D.pro to do scatter plots)
>
> I need to overlay a large number of scatter points in one plot, which consist of several groups. I want to assign different groups with different colors. The problems is they just tend to block each other due to the large number. Is a way to plot them with transparency or any other good solution?
>
> Thanks,
> Chengyu

Another solution might be to subset your data - i.e., if you have thousands of points per group, you might just plot every tenth one or whatever works for your data set.
Re: Plot scatter points with transparency [message #94587 is a reply to message #94580] Mon, 17 July 2017 03:56 Go to previous messageGo to next message
Markus Schmassmann is currently offline  Markus Schmassmann
Messages: 129
Registered: April 2016
Senior Member
On 07/15/2017 12:00 AM, chengyuxi34@gmail.com wrote:
> Is there a way to do transparent scatter plots?
> (Usually I use cgScatter2D.pro to do scatter plots)
>
> I need to overlay a large number of scatter points in one plot,
> which consist of several groups. I want to assign different groups
> with different colors. The problems is they just tend to block
> each other due to the large number. Is a way to plot them with
> transparency or any other good solution?
One approach is to edit the ps/epd/pdf or whatever file produced to make
the points transparent (don't ask me how...)

Another, randomize the order in which you make the plots, instead of
plotting one group after the other.

With the SCATTERPLOT function you can do it with

n=n_elements(x)
s=sort(randomu(seed,n))
s1=scatterplot(x[s],y[s],symbol='.',magnitude=whichGroup[s], rgb_table=myColors)

with cgScatter2D my guess is

cgScatter2D, x[s], y[s], color=group_colors[whichGroup[s]]

should work too.


Another approach is making a 2d histogram for each group, and then using
the result as index into a color table (maybe with a log in between).
Then you can use some kind of color mixing to calculate the final color.

w1=where(whichGroup eq 1)
h1=hist_2d(x[w1],y[w1],min1=0.,min2=0.,max1=1.,max2=1.,bin1= .1,bin2=.1)
...

That is more complicated than the other approaches, but the result is
likely to be clearer. You might want to increase the resolution of the
2d histogram to match the number of pixels in your output.

I hope one of the approaches described is helpful to you, good luck.

Markus
Re: Plot scatter points with transparency [message #94589 is a reply to message #94580] Mon, 17 July 2017 18:56 Go to previous message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
On Friday, July 14, 2017 at 6:00:31 PM UTC-4, ChengYu Xi wrote:
> Is there a way to do transparent scatter plots? (Usually I use cgScatter2D.pro to do scatter plots)
>
> I need to overlay a large number of scatter points in one plot, which consist of several groups. I want to assign different groups with different colors. The problems is they just tend to block each other due to the large number. Is a way to plot them with transparency or any other good solution?
>
> Thanks,
> Chengyu

The plot() function does exactly what you want. Here's a sketch of what you
might want to do:

colors = bytarr(n_elements(x))
p = plot(x, y, linestyle='', symbol='o', $
/sym_filled, transparency=50, rgb_table=34, vert_colors=colors)

Your data points are stored in x and y. The linestyle and symbol options plot the
data as circles that are not connected by lines. The flag /sym_filled fills the circles.
You'll want to choose (or create) a color table. rgb_table=34 is a rainbow table.
The vert_colors is an array of indexes into the color table, one for each point in the
plot. You'll have to figure out what the indexes should be for your data.
Finally, transparency=50 sets each plot symbol to 50% transparency. You'll want
to adjust this number to get the effect you want.

There are lots of other options, and I recommend reading the documentation for
the plot() function.

For what it's worth, the built-in function graphics routines are quite good for making
publication-quality plots.

All the best,

David
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Creating executable sav file
Next Topic: Writing to Multiple txt file with different names

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:36:39 PDT 2025

Total time taken to generate the page: 0.00458 seconds