Ok, today is a good day if you like colorful pictures! The goal today is to display the various colormaps that SageMath has to offer. Those colormaps can be called via
input: sorted(colormaps) output: ['Accent', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'Dark2', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'Paired', 'Pastel1', 'Pastel2', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Set1', 'Set2', 'Set3', 'Spectral', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cool', 'coolwarm', 'copper', 'cubehelix', 'flag', 'gist_earth', 'gist_gray', 'gist_heat', 'gist_ncar', 'gist_rainbow', 'gist_stern', 'gist_yarg', 'gnuplot', 'gnuplot2', 'gray', 'hot', 'hsv', 'jet', 'nipy_spectral', 'ocean', 'pink', 'prism', 'rainbow', 'seismic', 'spring', 'summer', 'tab10', 'tab20', 'tab20b', 'tab20c', 'terrain', 'winter']
To demonstrate these colormaps, I want to choose a few different interesting-looking matrices. For example, define the matrix by setting the entry equal to , defined over the field . In code,
M = matrix(GF(53),20,20,lambda i,j: i^2+j^2) show(M)
This gives the matrix
We can then generate the matrix plots using
for col in sorted(colormaps): matrix_plot(M,cmap=col)
To save each image, replace “matrix_plot(M,cmap=col)” with “matrix_plot(M,cmap=col).save(‘(i^2+j^2)_colormap_’+col+’.png’)” and then go to your files. They’ll all be listed there! Here they are:
If we replace the + with a -, meaning the entry is , then we get these instead:
Let’s choose a specific colormap to better see the difference and similarities between these two equations. For the matrices below, the left is defined with entry equal to , while the right is defined by , both over , the finite field of 53 elements. This means we only have entries between 0 and 52 and we work mod 53. The colormap is OrRd. Notice the parabolic shape on the left and the hyperbolic shape on the right.
And these are the same matrices with the Accent colormap.
That color scheme actually fits fairly nicely with the header color scheme, which inspires me. The background picture of the blog before this post was this:
But this meant that if you were on a long page, like Blog, then the pattern would tile and repeat. But they didn’t match up, so you got these horrible cuts that just look so bad, like this:
To fix this, we want to choose a picture where the top and bottom match up, and the left and right match up, so that when the pictures are tiled, they line up seamlessly. Let’s do this mathematically! The key is to use modular arithmetic.
If we limit the amount of colors to 13 (meaning we work in ), then we know that the coordinates will have the same color, i.e. we repeat every 13 pixels. In Sage, the finite field is written as , meaning Galois Field.
Keeping with the theme, let’s choose a matrix with entries , over . In code,
M = matrix(GF(13),13,13,lambda i,j: i^2+j^2) matrix_plot(M,cmap='Accent')
Then we are guaranteed a seamless connection. For the proof, we can check!
Or…just look at the background now!
Bonus Pic! This is a matrix defined over with entries . This collage also inspired the background, which is the very first one, Accent.
Thank you for reading!