Jan 26, 2010

More on Heatmap

A reader asks about this heatmap post on Flowing Data. Sure, we can do it easily with ArrayPlot. Grab the notebook here.

data = Import["ppg2008.csv"];

Grid[data]

Capture 

numbers = data[[2 ;; All, 2 ;; All]]; (* this is the data for heatmap *)
playernames = data[[2 ;; All, 1]]; (* for the labels *)
statnames = data[[1, 2 ;; All]]; (* for the labels *)

Then we need to scale the each column separately to [0,1].

newnumber = Transpose[Rescale[#] & /@ (Transpose[numbers])];

Then you can generate a simple heatmap simply by ArrayPlot[newnumber].

Of course, we like to add the labels with FrameTicks option. FrameTicks->{{left,right},{bottom,top}}  mark options specified separately for each edge. 

Transpose[{Range[Length[playernames]], playernames}] generate the list {{1, “player1”} … {50, “player50”}} to label the player names.

Transpose[{Range[Length[statnames]], Map[Rotate[#, 60 Degree] &, statnames]}] with this line, we can rotate the labels at the same time.

Here is the final product, click to see the full graphic.

NBAHeatmap

8 comments:

Anonymous said...

Thank you for posting this. The solution is simpler than I thought. Please keep up with the posting - they are very helpful.

Anonymous said...

Great!
I want more!!

Unknown said...

Great examples. I'll consider to reuse this for displaying realtime price evolution of securities from same sector :)

As a trader starting to link Mathematica to my trading app, I have a beginner's Mathematica question about FinancialData.

I would like to retrieve a set of current prices from a single query but if I'm using
Map[FinancialData, {"AAPL", "MSFT", "ORCL"}]
the mapping is done client side (my machine) and not from the server (FinancialData provider). This is critical as to fetch a realtime price takes already more than 1 second (measured from a Java J/Link program) then with mapping done locally this translates to 3 FinancialData queries or more than 3 seconds to get back the completed queries, for having them aggregated in a set of prices.
Is there a way to have Map operate from the server or another possible expression for having the set of prices from a single query?

Very best regards,
Max

Murta said...

Nice job!
I learn a lot from your examples...
tks

Anonymous said...

A follow-up question. Flowing Data had an article on treemap visulaizations several months ago.

http://flowingdata.com/2010/02/11/an-easy-way-to-make-a-treemap/

How would you approach this in Mathemaitca?

Asyrk said...

I get a black box instead of the heat map, does anybody know why does it happen?!

Cialis said...

This was so helpful. Thank you for sharing!

website heatmap said...

Quite interesting that such a simple tool can be so powerful in highlighting the core messages....thanks for sharing! Keep up the knowledge sharing, you're bound to help people!