4
$\begingroup$

I have a set of 1million 2D points and I would like to produce an image 200x200 pixels where each point will have the size of a pixel (no more). Additionally each point may repeats several times so I would like to add some weight on it (small number of repetitions ->Light Green , ... , large number of repetitions ->Dark Green)

I am experimenting with the following data set before I use the real one :

data = Flatten[
   Table[Table[{i, j} k, {i, 1, 50}, {j, 1, 50}], {k, 1, 10, .5}], 2];

So which is the correct PointSize in my case and how can I set the intensity of each point ?

I am not that experienced on Graphics so I would appreciate any insight.

$\endgroup$
4
  • $\begingroup$ PointeSize[0] is valid ? $\endgroup$
    – tchronis
    Mar 20, 2014 at 10:31
  • $\begingroup$ For the intensity, you could use different Opacity values for a given color or overlay several points with constant Opacity. $\endgroup$
    – Yves Klett
    Mar 20, 2014 at 10:46
  • $\begingroup$ Thank you @YvesKlett how can I overlay the points? $\endgroup$
    – tchronis
    Mar 20, 2014 at 10:50
  • 1
    $\begingroup$ Try this line to get an idea: Graphics[{PointSize[Large], Point[#[[1 ;; 2]], VertexColors -> Directive[Opacity[#[[3]]], Blue]] & /@ RandomReal[{0, 1}, {3000, 4}]}] $\endgroup$
    – Yves Klett
    Mar 20, 2014 at 11:12

2 Answers 2

3
$\begingroup$
data = Flatten[
   Table[Table[{i, j} k, {i, 1, 50, .3}, {j, 1, 50, .3}], {k, 1, 
     10, .3}], 2];
Dimensions@data (*{833776, 2}*)

You can also do something like: (here I've assumed that you know what is the range of the data - 500)

m = SparseArray[Rule[IntegerPart[#], #2
                    ] & @@@ Tally[(200. Round[data/500., 1/200.] + 1.)]];

ArrayPlot[m, PlotRangePadding -> 0, ImageSize -> {200, 200}, Frame -> False,
             ColorFunction -> (Blend[{LightGreen, Darker@Green}, #] &)]

enter image description here

$\endgroup$
2
  • 2
    $\begingroup$ With DensityHistogram there's no need to generate m: DensityHistogram[ data, PlotRangePadding -> 0, ImageSize -> {200, 200}, Frame -> False, ColorFunction -> (Blend[{LightGreen, Darker@Green}, #] &), PerformanceGoal :> "Speed" ] $\endgroup$ Mar 20, 2014 at 21:47
  • $\begingroup$ @ArgentoSapiens Good point, you can post an answer. It calculates quite a long time though. $\endgroup$
    – Kuba
    Mar 20, 2014 at 21:56
3
$\begingroup$

To answer the question of how to set the point size to precisely one pixel: use AbsolutePointSize[1].

PointSize specifies the point diameter relative to the graphics width. Points whose size is controlled by this directive change size when the graphics is resized.

AbsolutePointSize will use printer's points for printable vector graphics (such as PDF) and pixels for on-screen display. AbsolutePointSize[1] will always display with a diameter of 1 pixel, regardless of the screen resolution. (This is not what the docs say, but this is what happens. The point-to-pixel ratio might be adjustable somewhere in the option inspector, not sure about this. By default it's 1, i.e. 72 "dpi".) When using AbsolutePointSize, the point size will be independent of the graphics size.

$\endgroup$
1
  • $\begingroup$ +1 Thanks @Szabolics I didn't suspect that. $\endgroup$
    – tchronis
    Mar 21, 2014 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.