ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 11 Jul 2022 19:35:26 +0200Color nodes of posethttps://ask.sagemath.org/question/63211/color-nodes-of-poset/I have a poset Q and an element alpha[4] of Q. If I type "alpha[4] in Q", Sage correctly responds "True".
However, when I ask Sage to plot Q with alpha[4] in a special color, I get a KeyError that looks like it can no longer identify alpha[4] as an element of Q. What is going on?
I can't attach screenshots, so here's the error message in text:
Q.plot(element_colors={"blue":[alpha[4]]})
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-27-a224aeb4e328> in <module>
----> 1 Q.plot(element_colors={"blue":[alpha[Integer(4)]]})
/ext/sage/9.4/local/lib/python3.9/site-packages/sage/combinat/posets/posets.py in plot(self, label_elements, element_labels, layout, cover_labels, **kwds)
2061 cover_labels = False
2062
-> 2063 return graph.plot(vertex_labels=label_elements,
2064 edge_labels=cover_labels,
2065 layout=layout,
/ext/sage/9.4/local/lib/python3.9/site-packages/sage/misc/decorators.py in wrapper(*args, **kwds)
489 options['__original_opts'] = kwds
490 options.update(kwds)
--> 491 return func(*args, **options)
492
493 #Add the options specified by @options to the signature of the wrapped
/ext/sage/9.4/local/lib/python3.9/site-packages/sage/graphs/generic_graph.py in plot(self, **options)
19991 ['black', 'purple', 'yellow', 'yellow']
19992 """
> 19993 return self.graphplot(**options).plot()
19994
19995 def show(self, method="matplotlib", **kwds):
/ext/sage/9.4/local/lib/python3.9/site-packages/sage/graphs/generic_graph.py in graphplot(self, **options)
19639 """
19640 from sage.graphs.graph_plot import GraphPlot
> 19641 return GraphPlot(graph=self, options=options)
19642
19643 def _rich_repr_(self, display_manager, **kwds):
/ext/sage/9.4/local/lib/python3.9/site-packages/sage/graphs/graph_plot.py in __init__(self, graph, options)
304
305 self.set_pos()
--> 306 self.set_vertices()
307 self.set_edges()
308
/ext/sage/9.4/local/lib/python3.9/site-packages/sage/graphs/graph_plot.py in set_vertices(self, **vertex_options)
492 colors = []
493 for i in vertex_colors:
--> 494 pos.extend([self._pos[j] for j in vertex_colors[i]])
495 colors.extend([i] * len(vertex_colors[i]))
496
/ext/sage/9.4/local/lib/python3.9/site-packages/sage/graphs/graph_plot.py in <listcomp>(.0)
492 colors = []
493 for i in vertex_colors:
--> 494 pos.extend([self._pos[j] for j in vertex_colors[i]])
495 colors.extend([i] * len(vertex_colors[i]))
496
KeyError: alpha[4]OliverPMon, 11 Jul 2022 19:35:26 +0200https://ask.sagemath.org/question/63211/Attribute error: "'Graphics' object has no attribute 'get_pos'" with plotting Hasse diagram of posethttps://ask.sagemath.org/question/50995/attribute-error-graphics-object-has-no-attribute-get_pos-with-plotting-hasse-diagram-of-poset/So I am trying to obtain the position dictionary used for displaying a poset P that can be used in the plotting of the Hasse diagram of P through the hasse_diagram() function.
To clarify, if I run the following code:
P = posets.BooleanLattice(3)
P.plot()
G = P.hasse_diagram().to_undirected()
G.plot()
The locations of the vertices of G do not line up with where the corresponding elements of the poset were. I know that we can save the position dictionary for graphs, but for whatever reason, I'm struggling with obtaining the position dictionary of elements in a poset. (With the specific posets I am working with, maintaining the position when obtaining the undirected Hasse diagram is important because I need a particular planar embedding which is not being preserved if I simply use the hasse_diagram() function in its canned form).
In the finite posets SageMath documentation, the `plot()` function says that it also accepts all options of `GenericGraph.plot` which should include the `save_pos` option and `get_pos()`. However, when I run
P = posets.BooleanLattice(3)
Pplot = P.plot(save_pos=True)
G = P.hasse_diagram().to_undirected()
position = Pplot.get_pos()
G.plot(pos = position)
I get an attribute error:
Error in lines 4-4
Traceback (most recent call last):
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1234, in execute
flags=compile_flags), namespace, locals)
File "", line 1, in <module>
AttributeError: 'Graphics' object has no attribute 'get_pos'
Is there any way to extract a position dictionary of a graphics object corresponding to the Hasse diagram of a poset?DerekHFri, 24 Apr 2020 23:58:54 +0200https://ask.sagemath.org/question/50995/Specify heights in Poset.plothttps://ask.sagemath.org/question/37756/specify-heights-in-posetplot/ Hi, I'm relatively new to Python and SAGE so please make it simple :)
Basically, I work with posets that are not ranked and I want to plot their Hasse Diagram. For the moment, I use Poset.plot() to display it but I can change to hasse.diagram().plot() if necessary.
My problem is the following : The posets that I work with come with an extra function that associate to every set an integer. Is there a way to use this function to specify the heights of the sets in my plot and not the default one ?
Thank you MthGThu, 01 Jun 2017 11:01:19 +0200https://ask.sagemath.org/question/37756/Poset plot is upside-downhttps://ask.sagemath.org/question/25359/poset-plot-is-upside-down/ Tried the following in smc
X = (24).divisors()
R = [(a,b) for a in X for b in X if a.divides(b)]
D = Poset([X,R])
D.plot()
The resulting plot is upside-down; that is "1" is at the top and "24" at the bottom.
How can I fix this?mgassMon, 29 Dec 2014 17:01:23 +0100https://ask.sagemath.org/question/25359/Orientation of poset plot in Sage 6.3 vs 6.4https://ask.sagemath.org/question/25192/orientation-of-poset-plot-in-sage-63-vs-64/In older versions of Sage (6.3 and below), plotting a poset (or an acyclic graph with layout = "acyclic") gives a directed graph with arrows pointing up.
However, it seems like in Sage 6.4, the arrows now point down (and the bottom element appears at the top).
Is this a bug? Or are there any options I can tweak to reverse the orientation? I would expect the "correct" behaviour to be the one with the arrows pointing up; the Sage reference on [layout_acyclic](http://www.sagemath.org/doc/reference/graphs/sage/graphs/digraph.html#sage.graphs.digraph.DiGraph.layout_acyclic) seems to agree.
(I noticed the discrepancy while running Sage 6.3 on the [Sage Cell Server](http://sagecell.sagemath.org/) and Sage 6.4 on [Sagemath Cloud](https://cloud.sagemath.com/))
Here's some code you can try:
Poset({0:[2],1:[2],2:[]}).show()ZeWed, 10 Dec 2014 10:07:32 +0100https://ask.sagemath.org/question/25192/how to plot poset and subposet in a graph?https://ask.sagemath.org/question/10937/how-to-plot-poset-and-subposet-in-a-graph/hot to put poset and subposet and order_filter and order_ideal in one graph,but different color?
PP = Posets(6)[18];show(PP,vertex_size=100,vertex_colors='yellow');
Q = PP.subposet([2,4]);Q;show(Q,vertex_size=100,vertex_colors='green')
PP.order_filter([3,2]);PP.order_ideal([4,3])cjshMon, 20 Jan 2014 03:13:46 +0100https://ask.sagemath.org/question/10937/png scale of Posets and order from left ro righthttps://ask.sagemath.org/question/10717/png-scale-of-posets-and-order-from-left-ro-right/Hi to all,
I am doing a project with Posets in Sage. What I want is to create Posets and O(P) to view a pattern based on the created (png) Posets, so that I can generalize the behavior of O(P). I have created the Posets, but it changes the order of the numbers in the Poset, which makes difficult to see the pattern. ( I cant upload images because of my Karma... :/)
For example, the labeling of the posets go, from left to right (when there are more nodes):
level Poset (connected)
2 4
1 3 2
0 1
1- How I can force to draw the picture (the png) to go in the ascending order, from left to right?
Also, when the posets have 12 or more elements, they are not readable, the labels are inserted inside the others...
2- How I can change the scale of the nodes and the scale of the arrows to be more readable??
Thak you!
Note: I am using
x = P2.plot() # P2 is a Poset
x.save("myfile.png") # save the Poset
ShariffSat, 09 Nov 2013 10:33:41 +0100https://ask.sagemath.org/question/10717/