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)
Monday, 22 June 2020
Separate y-axis on the right
Tuesday, 3 July 2018
Dash it all: Custom line styles
set term pdfcairo font "Chalkduster,15"
set out 'dashes.pdf'
set key samplen 12 opaque box
PI = acos(-1.)
set xrange [0:2*PI]
plot sin(x) dashtype '-' lw 3 t 'Sin(x)', \
sin(2*x) dashtype '.' lw 3 t 'Sin(2x)', \
sin(3*x) dashtype '. - _' lw 3 t 'Sin(3x)', \
0 not
Friday, 19 February 2016
A pm3d surface plot
# set up the terminal to be the interactive wxt display, # but with equal width and height set term wxt size 400,400 # we will be plotting a function of two variables, but we # don't want the default surface plot unset surface # view from above set view 0,90 # set the coloured "pm3d" plot (rather than the surface, # which we unset above) set pm3d # viewing from above, we don't want to have the z-axis # tick marks shown all bunched up unset ztics # now plot, with a title splot 'pot.dat' title "Potential"
It's not perfect. With a bit of tweaking with placement, the title could be centrally above the square of the plot and the whitespace more even in the frame, but it visualises the potential quite well.
