3
$\begingroup$

DensityHistogram has a function hf, which I believe allows you to alter what defines the colours (I presume hf stands for height function) at any coordinate.

The default is to take data points such as {x, y} and color the corresponding coordinate according to the number of {x, y} as a percentage of all data points {_, _}.

I want to instead color the x, y coordinate according to the number of data points {x, y, z}, as a percentage of all data points {x, y, _}.

To try and state it another way, I'd like the colours of each coordinate (x,y) of the final density map to be determined by Count[data, {x,y,z}]] / Count[data, {x,y,_}]]. By default the colours of each coordinate (x,y) are instead determined by Count[data, {x,y}]].

The particular problem I'm trying to solve is that I have data, where each data point looks like {Shortlisted, Grade 5, Female}. So the x axis for the final graph should be categories of recruitment, while the y axis is types of job, and the colour is the percentage of people in that specific x,y coordinate (category of recruitment and type of job) who are female determines the colour, rather than the total number of people in that coordinate, which is the default.

I've managed to do this using ListDensityPlot[appropriately altered data set,InterpolationOrder->0,...], but this leaves me with the problem of labelling (in text) the coordinates with both the percentage and absolute number of {x,y,z} - a task that is pretty easy in DensityHistogram, while ListDensityPlot has a different understanding of what the coordinates are, and I'm yet to work out how to apply some of the solutions on here for labelling 3d charts to my particular problem.

$\endgroup$
  • $\begingroup$ I don't understand this question, and perhaps others don't either. If you could rephrase it or explain it in more detail, it would surely help. In particular, I don't understand how you can count the number of triplets {x, y, z} (a three dimensional point) and then visualize the count/fraction on a two-dimensional grid. Surely this would require a 3D-dimensional grid. $\endgroup$ – C. E. Jan 19 '18 at 22:00
  • $\begingroup$ You are right in what you are saying about density maps, that they consist of three variables; an x and y coordinate, together with a third variable that determines the color. But in the sentence in your question, "I want to instead color the x, y coordinate according to the number of data points {x, y, z}", you appear to be talking about a four-dimensional space. You have in this sentence three coordinate variables plus a count variable, that makes four variables. $\endgroup$ – C. E. Jan 23 '18 at 21:46
2
$\begingroup$

The answer turned out to be:

data = Count[data, {x, y, z}]/Count[data, {x, y, _}];
ArrayPlot[data]
| improve this answer | |
$\endgroup$
  • $\begingroup$ @Isaac Is what I wrote in my answer now correct? $\endgroup$ – C. E. Jan 26 '18 at 10:17
  • $\begingroup$ @Isaac Makes sense. I'm glad it worked out eventually. $\endgroup$ – C. E. Jan 26 '18 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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