PermutaTriangle/Permuta

Show and export permutations

mchllbrt opened this issue · 6 comments

I'd like to be able to use p.show() to show the permutation p on screen (ascii style), possibly with options to show it in a browser, plot window or whatever.

Additionally p.export(format=svg), p.export(format=tikz) etc. for exporting permutations to use in other contexts.

Permpy has some code that may be useful, in the show() and to_tikz() commands of permutation.py. It generates tikz code, writes it to a file, runs the pdflatex command to compile to pdf, then opens the pdf. It works at least on linux and mac, not sure about Windows.

@jaypantone Yes, that code was moved into permuta wholesale.
I understand the use case here, but I feel like we have to look into what exactly the community standard is in the area. My timidity stems from plot and show being two completely different things in matplotlib and other graphics libraries. If we have a Perm.show function which both plots and shows the perm (and possibly more things), we're probably doing something that isn't considered good practice at all.

My immediate thought would be to introduce two methods, display and export, to each python class we want to be able to permform these on, like so:

from permuta import Perm, MeshPatt

p = Perm((0, 1, 2, 3))

p.display()
p.display(method="browser")
p.display(method="window")
p.display(method="pdf")

p.export()
p.export(file_name="my_perm.svg")
p.export(file_name="mytikz.tex", file_format="tikz")
p.export(file_name="my_perm.pdf")
p.export(file_name="pdfblob", file_format="pdf")

and keep the plot method as a matplotlib plotting function similar to what it is in the demo at the moment.

Another option would be to have a permuta.export and permuta.display functions that work similarly

from permuta import display, export
mp = MeshPatt(...)
export(mp, ...)
display(p, ...)

I agree completely. Just wanted to point out that that code was there, in case it's useful in any way.

@jaypantone It was very useful when I was looking into these things :)

We had a short discussion on this end and @ulfarsson and @mchllbrt find this agreeable. Thus this is the path we take and I will start working on this on a new branch.

#125
.to_svg() added

#127
.show() added