Skip to content

Commit

Permalink
sage.combinat: Add # optional - sage.plot
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed May 16, 2023
1 parent f6e39ab commit 8f24e58
Show file tree
Hide file tree
Showing 32 changed files with 238 additions and 215 deletions.
2 changes: 1 addition & 1 deletion src/sage/combinat/binary_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def show(self, with_leaves=False):
TESTS::
sage: t1 = BinaryTree([[], [[], None]])
sage: t1.show()
sage: t1.show() # optional - sage.plot
"""
try:
self.graph(with_leaves=with_leaves).show(layout='tree', tree_root=0, tree_orientation="down")
Expand Down
16 changes: 10 additions & 6 deletions src/sage/combinat/cluster_algebra_quiver/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def qmu_save(self, filename=None):
sage: Q = ClusterQuiver(['F',4,[1,2]])
sage: import tempfile
sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f:
sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f: # optional - sage.plot sage.symbolic
....: Q.qmu_save(f.name)
Make sure we can save quivers with `m != n` frozen variables, see :trac:`14851`::
Expand All @@ -751,7 +751,7 @@ def qmu_save(self, filename=None):
sage: T1 = S.principal_extension()
sage: Q = T1.quiver()
sage: import tempfile
sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f:
sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f: # optional - sage.plot sage.symbolic
....: Q.qmu_save(f.name)
"""
M = self.b_matrix()
Expand Down Expand Up @@ -1475,14 +1475,16 @@ def mutation_sequence(self, sequence, show_sequence=False, fig_size=1.2 ):
INPUT:
- ``sequence`` -- a list or tuple of vertices of ``self``.
- ``show_sequence`` -- (default: False) if True, a png containing the mutation sequence is shown.
- ``show_sequence`` -- (default: ``False``) if ``True``, a png containing the mutation sequence is shown.
- ``fig_size`` -- (default: 1.2) factor by which the size of the sequence is expanded.
EXAMPLES::
sage: Q = ClusterQuiver(['A',4])
sage: seq = Q.mutation_sequence([0,1]); seq
[Quiver on 4 vertices of type ['A', 4], Quiver on 4 vertices of type ['A', 4], Quiver on 4 vertices of type ['A', 4]]
[Quiver on 4 vertices of type ['A', 4],
Quiver on 4 vertices of type ['A', 4],
Quiver on 4 vertices of type ['A', 4]]
sage: [T.b_matrix() for T in seq]
[
[ 0 1 0 0] [ 0 -1 0 0] [ 0 1 -1 0]
Expand All @@ -1491,8 +1493,6 @@ def mutation_sequence(self, sequence, show_sequence=False, fig_size=1.2 ):
[ 0 0 -1 0], [ 0 0 -1 0], [ 0 0 -1 0]
]
"""
from sage.plot.plot import Graphics
from sage.plot.text import text
n = self._n
m = self._m
if m == 0:
Expand Down Expand Up @@ -1520,9 +1520,13 @@ def mutation_sequence(self, sequence, show_sequence=False, fig_size=1.2 ):
quiver_sequence.append( copy( quiver ) )

if show_sequence:
from sage.plot.plot import Graphics
from sage.plot.text import text

def _plot_arrow( v, k, center=(0,0) ):
return text(r"$\longleftrightarrow$",(center[0],center[1]), fontsize=25) + text(r"$\mu_"+str(v)+"$",(center[0],center[1]+0.15), fontsize=15) \
+ text("$"+str(k)+"$",(center[0],center[1]-0.2), fontsize=15)

plot_sequence = [ quiver_sequence[i].plot( circular=True, center=(i*width_factor,0) ) for i in range(len(quiver_sequence)) ]
arrow_sequence = [ _plot_arrow( sequence[i],i+1,center=((i+0.5)*width_factor,0) ) for i in range(len(sequence)) ]
sequence = []
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/crystals/crystals.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
One can get (currently) crude plotting via::
sage: Tab.plot()
sage: Tab.plot() # optional - sage.plot
Graphics object consisting of 52 graphics primitives
If dot2tex is installed, one can obtain nice latex pictures via::
Expand Down
6 changes: 3 additions & 3 deletions src/sage/combinat/crystals/letters.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ cdef class Crystal_of_letters_type_E6_element(LetterTuple):
sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None)
True
sage: G = C.digraph()
sage: G.show(edge_labels=true, figsize=12, vertex_size=1)
sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # optional - sage.plot
"""

def _repr_(self):
Expand Down Expand Up @@ -1751,7 +1751,7 @@ cdef class Crystal_of_letters_type_E6_element_dual(LetterTuple):
sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None)
True
sage: G = C.digraph()
sage: G.show(edge_labels=true, figsize=12, vertex_size=1)
sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # optional - sage.plot
"""

def _repr_(self):
Expand Down Expand Up @@ -1911,7 +1911,7 @@ cdef class Crystal_of_letters_type_E7_element(LetterTuple):
sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None)
True
sage: G = C.digraph()
sage: G.show(edge_labels=true, figsize=12, vertex_size=1)
sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # optional - sage.plot
"""

def weight(self):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/crystals/mv_polytopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def plot(self, P=None, **options):
sage: MV = crystals.infinity.MVPolytopes(['C', 2])
sage: b = MV.highest_weight_vector().f_string([1,2,1,2,2,2,1,1,1,1,2,1])
sage: b.plot()
sage: b.plot() # optional - sage.plot
Graphics object consisting of 12 graphics primitives
Here is the above example placed inside the ambient space
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/dyck_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ def plot(self, **kwds):
EXAMPLES::
sage: w = DyckWords(100).random_element()
sage: w.plot()
sage: w.plot() # optional - sage.plot
Graphics object consisting of 1 graphics primitive
"""
from sage.plot.plot import list_plot
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/finite_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -9708,7 +9708,7 @@ def plot(self):

TESTS::

sage: FiniteStateMachine([('A', 'A', 0)]).plot()
sage: FiniteStateMachine([('A', 'A', 0)]).plot() # optional - sage.plot
Graphics object consisting of 3 graphics primitives
"""
return self.graph(edge_labels='words_in_out').plot()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/fully_commutative_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def plot_heap(self):
EXAMPLES::
sage: FC = CoxeterGroup(['B', 5]).fully_commutative_elements()
sage: FC([3,2,4,3,1]).plot_heap()
sage: FC([3,2,4,3,1]).plot_heap() # optional - sage.plot
Graphics object consisting of 15 graphics primitives
.. PLOT::
Expand Down
13 changes: 7 additions & 6 deletions src/sage/combinat/fully_packed_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class FullyPackedLoop(Element, metaclass=InheritComparisonClasscallMetaclass):
The class also has a plot method::
sage: fpl.plot()
sage: fpl.plot() # optional - sage.plot
Graphics object consisting of 3 graphics primitives
which gives:
Expand Down Expand Up @@ -781,7 +781,7 @@ def plot(self, **options):
sage: A = AlternatingSignMatrix([[0, 1, 0], [1, -1, 1], [0, 1, 0]])
sage: fpl = FullyPackedLoop(A)
sage: fpl.plot()
sage: fpl.plot() # optional - sage.plot
Graphics object consisting of 3 graphics primitives
The resulting graphics is as follows
Expand All @@ -798,7 +798,7 @@ def plot(self, **options):
sage: A = AlternatingSignMatrix([[0, 1, 0], [1, -1, 1], [0, 1, 0]])
sage: fpl = FullyPackedLoop(A)
sage: fpl.plot(link_color_map='rainbow')
sage: fpl.plot(link_color_map='rainbow') # optional - sage.plot
Graphics object consisting of 3 graphics primitives
.. PLOT::
Expand All @@ -811,8 +811,9 @@ def plot(self, **options):
You can plot the 42 fully packed loops of size `4 \times 4` using::
sage: G = [fpl.plot(link_color_map='winter', loop_color='black') for fpl in FullyPackedLoops(4)]
sage: graphics_array(G, 7, 6)
sage: G = [fpl.plot(link_color_map='winter', loop_color='black') # optional - sage.plot
....: for fpl in FullyPackedLoops(4)]
sage: graphics_array(G, 7, 6) # optional - sage.plot
Graphics Array of size 7 x 6
.. PLOT::
Expand All @@ -833,7 +834,7 @@ def plot(self, **options):
....: 00000000+-0000+00000000000000+0000000000"
sage: a = matrix(20, [{'0':0, '+':1, '-': -1}[i] for i in s])
sage: fpl = FullyPackedLoop(a)
sage: fpl.plot(loop_fill=True, loop_color_map='rainbow')
sage: fpl.plot(loop_fill=True, loop_color_map='rainbow') # optional - sage.plot
Graphics object consisting of 27 graphics primitives
.. PLOT::
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/interval_posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,13 @@ def plot(self, **kwds):
EXAMPLES::
sage: ti = TamariIntervalPosets(4)[2]
sage: ti.plot()
sage: ti.plot() # optional - sage.plot
Graphics object consisting of 6 graphics primitives
TESTS::
sage: ti = TamariIntervalPoset(3, [[2,1], [2,3]])
sage: ti.plot()
sage: ti.plot() # optional - sage.plot
Graphics object consisting of 6 graphics primitives
"""
c0 = 'blue' # self.latex_options()["color_increasing"]
Expand Down
8 changes: 4 additions & 4 deletions src/sage/combinat/k_regular_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,20 +1223,20 @@ def from_recurrence(self, *args, **kwds):
of non-zero elements in the generalized Pascal's triangle (see
[LRS2017]_)::
sage: U = Seq2.from_recurrence(M=1, m=0,
sage: U = Seq2.from_recurrence(M=1, m=0, # optional - sage.symbolic
....: coeffs={(0, 0): 1},
....: initial_values={0: 0, 1: 1},
....: inhomogeneities={1: P})
sage: (U - Seq2(SB)).is_trivial_zero()
sage: (U - Seq2(SB)).is_trivial_zero() # optional - sage.symbolic
True
::
sage: U = Seq2.from_recurrence(M=1, m=0,
sage: U = Seq2.from_recurrence(M=1, m=0, # optional - sage.symbolic
....: coeffs={},
....: initial_values={0: 0, 1: 1},
....: inhomogeneities={0: SB, 1: P})
sage: (U - Seq2(SB)).is_trivial_zero()
sage: (U - Seq2(SB)).is_trivial_zero() # optional - sage.symbolic
True
Number of Unbordered Factors in the Thue--Morse Sequence, but partly
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/nu_dyck_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def plot(self, **kwds):
EXAMPLES::
sage: NDW = NuDyckWord('010','010')
sage: NDW.plot()
sage: NDW.plot() # optional - sage.plot
Graphics object consisting of 1 graphics primitive
"""
from sage.plot.plot import list_plot
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/ordered_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def plot(self):
o o o
|
o
sage: p.plot()
sage: p.plot() # optional - sage.plot
Graphics object consisting of 10 graphics primitives
.. PLOT::
Expand All @@ -691,7 +691,7 @@ def plot(self):
2 3 5
|
4
sage: g.plot()
sage: g.plot() # optional - sage.plot
Graphics object consisting of 10 graphics primitives
.. PLOT::
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,8 +1726,8 @@ def show(self, representation="cycles", orientation="landscape", **args):
EXAMPLES::

sage: P20 = Permutations(20)
sage: P20.random_element().show(representation="cycles") # optional - sage.graphs
sage: P20.random_element().show(representation="chord-diagram") # optional - sage.graphs
sage: P20.random_element().show(representation="cycles") # optional - sage.graphs sage.plot
sage: P20.random_element().show(representation="chord-diagram") # optional - sage.graphs sage.plot
sage: P20.random_element().show(representation="braid") # optional - sage.plot
sage: P20.random_element().show(representation="braid", # optional - sage.plot
....: orientation='portrait')
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/plane_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def plot(self, show_box=False, colors=None):
EXAMPLES::

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]])
sage: PP.plot()
sage: PP.plot() # optional - sage.plot
Graphics object consisting of 27 graphics primitives
"""
from sage.functions.trig import cos, sin
Expand Down Expand Up @@ -764,7 +764,7 @@ def plot3d(self, colors=None):
EXAMPLES::

sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]])
sage: PP.plot3d()
sage: PP.plot3d() # optional - sage.plot
Graphics3d Object
"""
if colors is None:
Expand Down
Loading

0 comments on commit 8f24e58

Please sign in to comment.