Plot scatter points with transparency [message #94580] |
Fri, 14 July 2017 15:00  |
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 #94587 is a reply to message #94580] |
Mon, 17 July 2017 03:56   |
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  |
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
|
|
|