Friday, 9 August 2024

Matrix shading in Mathematica

Not exactly plotting, but at least data visualisation ... 

I have a matrix which looks as follows, generated here in Mathematica from a 4x4 identity matrix and a tensor product of Pauli matrices:


H := 5.907  IdentityMatrix[4] + .2183  KroneckerProduct[
    PauliMatrix[3], IdentityMatrix[2]] -
  6.125  KroneckerProduct[IdentityMatrix[2], PauliMatrix[3]] -
  2.143  (KroneckerProduct[PauliMatrix[1], PauliMatrix[1]] +
     KroneckerProduct[PauliMatrix[2], PauliMatrix[2]]);
 

H // MatrixForm

what I'd like to do is highlight the block diagonal bits - i.e. elements (1,1), (4,4) and the 2x2 block in the middle. From some searching of the internet (particularly this useful page) and the Mathematica documentation, I see that the Background attribute can be applied to a Grid view of the matrix:

bg = {None,
   None, {{1, 1} -> LightGreen, {4, 4} ->
     LightGreen, {{2, 3}, {2, 3}} -> LightGreen}};

Grid[H, Background -> bg]

which has indeed highlighted the elements that I wanted it to, but at the expense of no longer using the brackets of MatrixForm.  I you ask for this to be printed in MatrixForm, the background colouring disappears.  As far as I have been able to work out, the Background attribute cannot be combined with MatrixForm.  Oh well, the blocking is still as I wanted.

The syntax for Background is given in the hyperlink above.

Thursday, 4 January 2024

Gnuplot 6.0.0

 I noticed that Gnuplot 6.0.0 is out.  Details of new features can be seen in the release notes.  I'm excited about the possibility of sector plots, in particular, it can make "polar equivalent to sparse-matrix heatmaps."  This is a kind of plot I do actually need to make for my research, and have outsourced the work to knowledgeable postdocs, or made somewhat ugly ones with matplotlib.  I'm keen to see what I can do with Gnuplot (while acknowledging that it is me, rather than matplotlib per se that stop me from making the plots I want to with mpl)