Mathematica ListPlot question

Discussion in 'Physics & Math' started by AlphaNumeric, Jan 16, 2011.

  1. AlphaNumeric Fully ionized Registered Senior Member

    Messages:
    6,702
    I have a set of data points in \(\mathbb{R}^{3}\) of the form \((x,y,f(x,y))\). I want to plot a 2d graph where (x,y) defines the location of the point and f(x,y) its colour. How do I do this?

    I know how to do it using ListPlot3D, you make the colour coding function Hue[z] = Hue[f(x,y)] but you end up with a 3d scatter plot which is colour coded. Normally I'd not mind this, as it illustrates the nature of f(x,y) both by height and colour but if you're trying to render 200,000 points Mathematica lapses into a 'Running' coma. Given Mathematica's love of nifty ways to display data surely something like colour coding a 2d plot using a scalar function dependent on the point's location is something commonly wanted but for the life of me I can't seem to find it using the Help or web documentation. A few things I've found online involve annoying hacks to generate lists of colours to feed into PlotStyle but surely there's an inbuilt way?

    In the hopes of possibly spurring a few people into some Googling if the first person to provide the answer is someone I consider a crank as 'payment' you get a single use 'AlphaNumeric must play nice' credit*. By that I mean that if you and I are squaring off in a thread on some BS crank nonsense you're allowed to invoke this and I will then conform to the alpha rules in our 'discussion', even if you didn't make the thread and its not an alpha rules thread.

    * Single use and cannot be used in conjunction with any other offer. Expires January 1 2012. Cash value 0.0000 cents. Check in store for details.
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. temur man of no words Registered Senior Member

    Messages:
    1,330
    Did you try ContourPlot ?
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. prometheus viva voce! Registered Senior Member

    Messages:
    2,045
    Or indeed, ListContourPlot?
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. AlphaNumeric Fully ionized Registered Senior Member

    Messages:
    6,702
    That would work if the (x,y) coords formed a convex hull but they don't. Mathematica tries to fill in the regions between points in an intelligent way and it ends up plotting a contour region whose boundary is quite different to what it should be. ReliefPlot does similar stuff but it requires the (x,y) coordinates be on a regular lattice, which mine aren't.

    I've got a very dubious hacked way of doing it using the fact Mathematica will plot different data sets in different colours. If A and B are two lists of points, ie A = {p1,p2,...} etc, then ListPlot[{A,B}] causes points n A to be coloured differently than those in B and you can specify what colour by something like PlotStyle->{Red,Blue}. To get A's p1 and p2 coloured differently you've got to restructure A to be of the form A = {{p1},{p2},....} so Mathematica thinks each point is in different set and then I have to make a table of colours of length equal to A. I can write a Module[{},...] function to do this for me each time but it takes a while to render it so if there's a native way of doing it it'd likely be faster.
     
  8. RJBeery Natural Philosopher Valued Senior Member

    Messages:
    4,222
    Bro my life is complex enough without trying to see you as a human with a sense of humor, etc. Pretty funny though
    What do you mean by this? Can you scale the data to fit the functional requirements?
     
  9. rpenner Fully Wired Valued Senior Member

    Messages:
    4,833
    I don't have Mathematica, could you critique these?

    data = {{ 0,0,1}, {2,2,0.5}, {0,1,0}, {1, 0, 5}}
    ListPointPlot3D[data, ColorFunction -> "Rainbow"]

    zrange = Max[data[[All, 3]]] - Min[data[[All, 3]]]
    zmin = Min[data[[All, 3]]]
    ListPlot[data[[All, 1;;2]], PlotStyle-> (Hue[(#-zmin)/zrange,1,0.5+(#-zmin)*0.5/zrange]) & /@ data[[All, 3]]]

    ListPlot[data[[All, 1;;2]], PlotStyle-> (ColorData["Rainbow"][(#-zmin)/zrange]) & /@ data[[All, 3]]]
     
  10. Beer w/Straw Transcendental Ignorance! Valued Senior Member

    Messages:
    6,549
    I thought, rpenner, worked closely with Mathematica. He seemed all too eager to dis Maple once. Sure, I couldn't divide 1 by 0 in Maple but that still doesn't let him off the hook for being heretic puke scum.
     
    Last edited: Jan 18, 2011
  11. rpenner Fully Wired Valued Senior Member

    Messages:
    4,833
    I reviewed Mathematica 3 near the time it came out. I also completed a class in programming Mathematica some 15+ years ago. I also link to Mathematica-backed sites for calculations, since I know of no Maple-backed sites. I will even admit to owning a copy of A New Kind of Science, but I never drank the Kool Aid.

    Besides, the Orthodox church uses Macsyma exclusively, so why all the fuss?
     
  12. RJBeery Natural Philosopher Valued Senior Member

    Messages:
    4,222
    Mathematica is more powerful than Maple but it's also much, much more expensive. It's also owned by an egomaniac that seems to eschew conventional notation for the sole purpose of being a pain in the ass.
     
  13. Beer w/Straw Transcendental Ignorance! Valued Senior Member

    Messages:
    6,549
    I was bored.

    And wanting to trap you, in case I had Mathematica questions, I'd know who to ask

    Please Register or Log in to view the hidden image!

     
  14. RJBeery Natural Philosopher Valued Senior Member

    Messages:
    4,222
    BTW I also read A New Kind of Science and I can boil the 1000+ pages down to a 2 statements:

    1) Sometimes, simple rules applied repeatedly on a system can produce incredibly complex and apparently sophisticated behavior that occasionally has an analogue to the real world.

    2) This concept (pioneered by me, STEPHEN WOLFRAM) will open a whole new world to us...although rather than show any practical applications I'm going to fill the rest of the book with pretty pictures that made me say wow.
     
  15. Beer w/Straw Transcendental Ignorance! Valued Senior Member

    Messages:
    6,549
    Wait.. Did you actually want the output?


    http://img412.imageshack.us/f/78660130.jpg/
     
  16. funkstar ratsknuf Valued Senior Member

    Messages:
    1,390
    Aaaargh!

    *winds up rant...*
    Oh. Well, alright then.

    *deflates*
     
  17. Beer w/Straw Transcendental Ignorance! Valued Senior Member

    Messages:
    6,549
    I've not read A New Kind of Science -I didn't like the title.

    You guys were privy to Kool Aid though

    Please Register or Log in to view the hidden image!



    I have to re-evaluate.
     
  18. AlphaNumeric Fully ionized Registered Senior Member

    Messages:
    6,702
    Sorry for the delayed reply, I use Orange mobile broadband at home and for some reason their servers regularly 'glitch', turn on the 'adult content blocker', don't allow access to my account settings and since www.sciforums.com is classified 'adult' by their content filter I can't access SciForums. I thought it might be due to the adverts if you don't log in but the Ubuntu help forums are also blocked!! Apparently 'computing' is too adult to be allowed by default.

    Anyway....

    I'm regularly called a shining wit by people who suffer from 'spoonerism Tourettes'.

    No. as I explicitly want the (x,y) coordinates computed, mapping them all to a structured lattice would destroy much of the features I want to highlight. And I'd have to do it for a different layout each time, as I'm doing this for loads of cases.

    Rpenner, looks like your method was similar to mine. The code I used is of the following form :

    List 1 is a list of the (x,y) points, List 2 is the height z.

    ListPlot[Transpose[{list1}],PlotStyle->Map[Hue,colourscale*list2/(2*Max[list2])]]

    'colourscale' sets how many cycles through the colour wheel the plot will do. The 'Transpose[{list1}]' is needed so that Mathematica views each 2d point as belonging to a different set, else it'd colour them all the same. On my 2.4GHz computer a list of about 200,000 points colour coded as such takes 30~60 seconds to load. Down sampling helps a lot!

    I suppose in the end the coding is pretty short, it just needs a pre-processing step to split the 3d coordinate to a 2d and a scalar but that's easy to do with some index trickery.
     

Share This Page