so yesterday I tried to visualize a graph in the form of a matrix. A lot of people helped me in the forum and the chat. I ended up with turning the numerical values in my matrix to RGB values. So now I have e.g.:
using FileIO
using Images
c = RGB{Normed{UInt8,8}}[
RGB{N0f8}(1.0,1.0,1.0) RGB{N0f8}(0.0,0.502,0.0) RGB{N0f8}(1.0,0.0,0.0);
RGB{N0f8}(1.0,0.0,0.0) RGB{N0f8}(1.0,1.0,1.0) RGB{N0f8}(0.0,0.0,0.0);
RGB{N0f8}(0.0,0.502,0.0) RGB{N0f8}(0.0,0.0,0.0) RGB{N0f8}(0.0,0.502,0.0)]
save("image.png", c) # For jupyter use FileIO.save("image.png", c)
Problem: I get an image of 3x3 pixels whereas is want a picture like
If anyone could help me figure out how to make my pixels huge, I’d be in love forever.The best szenario would be to define an image size nd then just have it scale automatically becuse the size of the matrix will change.
You should be able to do this natively from Images.jl by specifying the interpolation type for imresize, but there’s a longstanding issue: https://github.com/JuliaImages/ImageTransformations.jl/issues/51. It’s not a complicated fix, but nobody’s taken the time to do it yet.
using Images, Gaston
c = RGB{Normed{UInt8,8}}[
RGB{N0f8}(1.0,1.0,1.0) RGB{N0f8}(0.0,0.502,0.0) RGB{N0f8}(1.0,0.0,0.0);
RGB{N0f8}(1.0,0.0,0.0) RGB{N0f8}(1.0,1.0,1.0) RGB{N0f8}(0.0,0.0,0.0);
RGB{N0f8}(0.0,0.502,0.0) RGB{N0f8}(0.0,0.0,0.0) RGB{N0f8}(0.0,0.502,0.0)];
cc = channelview(c).*255; # convert to a 3-D array of RGB values
imagesc(cc,Axes(size="square",tics=:off))
Following up on yesterday’s discussion, here is what I do in Jupyterlab:
using Plots
#... like yesterday
function num2col(i)
if i == 0
return colorant"white"
elseif i == 1
return colorant"green"
elseif i == 2
return colorant"red"
else
return colorant"black"
end
end
#
mat = [0 3; 2 1]
#
plot(num2col.(mat),xaxis=nothing,yaxis=nothing)
I suspect the trick is to plot the matrix, and then use savefig – instead of just saving the matrix??
To adjust the size of the plot, you can use the size keyword of the plot function. You can, of course, also scale the svg file (or pdf or png) in your word processor.
Here, function distinguishable_colors() gives maximally distinguishable colors where the first argument gives the number of colors, and the optionally second argument gives a “seed” for picking the colors. (The seed can be a “scalar” color, or a vector of colors, I think.)
Works correctly for me in my Win10 and WSL machines but can reproduce this issue in a CentosOS machine.
Have an idea where it might coming from but puzzled with this machines discrepancy. Better move this ito a GMT.jl issue
For the record, this issue has been fixed in the GMT master and will be part of next official release. The compiled Windows installer (GMT 6.2.0dev) provided by joa-quim does not show the bug: