Opened 4 years ago

Last modified 3 years ago

#20343 needs_work enhancement

Adding sage/misc/tikzpicture.py

Reported by: slabbe Owned by:
Priority: major Milestone: sage-7.2
Component: misc Keywords:
Cc: dkrenn, jipilab Merged in:
Authors: Sébastien Labbé Reviewers: Jean-Philippe Labbé
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by slabbe)

Importing TikzPicture class from my optional Sage package slabbe-0.2.spkg into Sage.

One example:

sage: from sage.misc.tikzpicture import TikzPicture
sage: V = [[1,0,1],[1,0,0],[1,1,0],[0,0,-1],[0,1,0],[-1,0,0],[0,1,1],[0,0,1],[0,-1,0]]
sage: P = Polyhedron(vertices=V).polar()
sage: s = P.projection().tikz([674,108,-731],112)
sage: t = TikzPicture(s)
sage: t.pdf()

Second example:

sage: g = graphs.PetersenGraph()
sage: %time _ = TikzPicture(latex(g), standalone_options=["border=4mm"], usepackage=['tkz-graph']).pdf()
CPU times: user 3.52 ms, sys: 12.7 ms, total: 16.2 ms
Wall time: 2.24 s     

compared to using view (which crops the vertices and creates two pages pdf on mac):

sage: %time view(g, tightpage=True)               
CPU times: user 126 ms, sys: 85 ms, total: 211 ms 
Wall time: 6.06 s

Also, if dot2tex and graphviz available:

sage: t = TikzPicture.from_graph(g, prog='dot')  # optional: dot2tex

I intend to make further improvements to this module during the next year. Also, I will wait until somebody tells me he is willing to review this module before publishing a branch here.

Meanwhile any user can use this tikzpicture module by installing my package:

sage -pip install slabbe

and

sage: from slabbe import TikzPicture

Change History (12)

comment:1 Changed 4 years ago by slabbe

  • Description modified (diff)

comment:2 Changed 4 years ago by slabbe

  • Branch set to u/slabbe/20343
  • Commit set to 476b574c4198115e6e98e3396ed32f4b95077c35
  • Status changed from new to needs_review

New commits:

476b57420343: Adding tikzpicture.py in sage/misc

comment:3 Changed 4 years ago by slabbe

  • Description modified (diff)

comment:4 Changed 4 years ago by slabbe

  • Summary changed from Adding sage/misc/tikz_picture.py to Adding sage/misc/tikzpicture.py

comment:5 follow-up: Changed 4 years ago by dkrenn

  • Cc dkrenn added

A comment:

t = TikzPicture(latex(transducers.GrayCode()))
t.pdf()

does not work as the preamble is not set correctly. However, there is

from sage.combinat.finite_state_machine import setup_latex_preamble
setup_latex_preamble()

(as well as the corresponding function in sage.graphs.graph_latex) to set this correctly, but it seems to be ignored by TikzPicture.

In contrast,

view(transducers.GrayCode())

works, but I have no idea if setup_latex_preamble is called (not needed to be done manually) or if tikz is included anyways.

comment:6 in reply to: ↑ 5 ; follow-up: Changed 4 years ago by slabbe

Replying to dkrenn:

A comment:

t = TikzPicture(latex(transducers.GrayCode()))
t.pdf()

does not work as the preamble is not set correctly.

As it is now, the user must set the libraries. This should work:

t = TikzPicture(latex(transducers.GrayCode()), tikzlibraries=['automata'])
t.pdf()

I am still not sure about the proper way to choose the arguments for the __init__ function and their especially their default values. Should the arguments be empty by default? equal to the current sage latex preamble? or full of a big load of libraries?

comment:7 in reply to: ↑ 6 Changed 4 years ago by dkrenn

Replying to slabbe:

Replying to dkrenn:

A comment:

t = TikzPicture(latex(transducers.GrayCode()))
t.pdf()

does not work as the preamble is not set correctly.

As it is now, the user must set the libraries. This should work:

t = TikzPicture(latex(transducers.GrayCode()), tikzlibraries=['automata'])
t.pdf()

Works, thanks.

I am still not sure about the proper way to choose the arguments for the __init__ function and their especially their default values. Should the arguments be empty by default? equal to the current sage latex preamble? or full of a big load of libraries?

Without much thinking, I vote for: The second, equal to the current sage latex preamble.

comment:8 Changed 4 years ago by git

  • Commit changed from 476b574c4198115e6e98e3396ed32f4b95077c35 to 4ae7f63de1517e4c483e500757989b6efde5b785

Branch pushed to git repo; I updated commit sha1. New commits:

751209120343: Adding tikzpicture.py in sage/misc
4ae7f6320343: improving the default argument choices for TikzPicture

comment:9 Changed 4 years ago by slabbe

  • Description modified (diff)

comment:10 Changed 3 years ago by slabbe

  • Branch u/slabbe/20343 deleted
  • Commit 4ae7f63de1517e4c483e500757989b6efde5b785 deleted
  • Description modified (diff)

My module has evolved in my package slabbe, therefore the branch here is not up to date anymore. Also, I intend to make it more general during the next year allowing any content not only tikzpicture code. Therefore, I deleted the branch posted here.

comment:11 Changed 3 years ago by slabbe

  • Description modified (diff)
  • Status changed from needs_review to needs_work

Changing status to needs work.

comment:12 Changed 3 years ago by jipilab

  • Cc jipilab added
  • Reviewers set to Jean-Philippe Labbé

As a follow-up ticket to make use of this is #22506.

Note: See TracTickets for help on using tickets.