Friday, April 3, 2009

2D color maps in gnuplot 4.2

I was working on a school project about MLP and I had some output data in this form:

[x, y, category]
------------------
-4.82 -2.906 -1.0
-3.224 2.244 -1.0
-1.342 0.876 1.0
3.383 -2.237 -1.0
-1.665 -4.269 -1.0
-0.154 -0.042 1.0
2.148 1.662 0.0
------------------

And I wanted to make a colored map where the color of the points (first two columns) is dependent on category (the last column). Cause it's not a trivial task I wanted to share with solution I found. Here you can find the answer: http://www.gnuplot.info/faq/faq.html#SECTION000511000000000000000

For those who don't like to leave my blog there is the code:
gnuplot> set view map
gnuplot> set pm3d map
gnuplot> splot "test_map.dat" with points palette pt 9
And here is an example of what it can do:

Of course you can define your own colors or shapes of the points.

5 comments:

  1. if i have the category change with respect to time, how do i set the color map to be fix in color range..?

    ReplyDelete
    Replies
    1. Sorry for late reply. I don't know about a solution in gnutplot itself. I would preprocess the data before, so that the category is not changing with time. If the relationship is linear, just substract the time (weighted by some constatnt) from the category value.

      Delete
  2. Thank you! as incredibly simple as this might seem it can be hard to find online.

    I used it for something I'm working on and also wrote a bit about it so others like me might find it.

    ReplyDelete
  3. Thank you. This is really cool!

    ReplyDelete