I’m trying to visualize some data where I want to see some kind of distribution a (small) set of per sample distributions.
I doubt that the description makes much sense, but this MWE creates the type of figure I would like to see by just mapping values to a color manually to create an image:
using Plots
# This creates 21 samples with three sets of data in each sample
dummydata = [(0.1:0.1:x, 0.2:0.2:x, 0.3:0.3:x) for x in 0:0.05:1];
function colormatrix(pdata, cms)
z = fill(colorant"white", length(pdata), maximum(x -> sum(length, x), pdata)+1)
for (i, row) in enumerate(pdata)
offs = 0
for (cm, series) in zip(cms, row)
nelems = length(series)
nelems > 0 || continue
z[i, 1+offs:nelems+offs] .= cm[series]
offs += nelems
end
end
return z
end
plot(colormatrix(dummydata, (cgrad(:reds), cgrad(:blues), cgrad(:greens))))
The problem with the above approach is that I want to do this for a couple of million samples and the plot command either chokes or produces an invisibly thin horizontal line (as the x-axis has much fewer values than the y-axis).
If I instead make z
an array of floats and let plots.heatmap
handle the image generation I get something which looks good, but I can’t find a good way to separate the ranges of the colorgradient so the series
will blend into each other.
I can ensure that each series
(as used in colormatrix
) lies within a distinct numeric range (e.g. first series in 0-1, second in 2-3 etc.) in case that can be helpful.
I also can’t find what trick Plots.heatmap
uses to avoid the ‘too many pixels’ problem. Can one apply it to a matrix of Color
s? I have tried using aspect_ratio
set to 1
or :equal
but it does not help (enough). Setting size
does not help either.
I don’t have to use Plots
for this btw, its just what I have tried so far.