ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 10 Jul 2018 12:11:12 -0500graph vertex labellinghttp://ask.sagemath.org/question/42892/graph-vertex-labelling/I have a graph (poset actually) that has a rational function labelling each vertex. I would like to show just the edges and the vertex labels. If I try to set `vertex_shape='None'` I get a crash deep in matplotlib. If I try anything else I get the marker symbol printed over the label. For example
P = RootSystem(['A',3]).root_poset()
P.show(vertex_color='white')
Will show the graph with circles over the labels. If I shrink the labels, then the edges cover the labels.
If I do
P = RootSystem(['A',3]).root_poset()
P.show(vertex_color='white', vertex_shape='None')
there is a strange crash.deinstTue, 10 Jul 2018 12:11:12 -0500http://ask.sagemath.org/question/42892/display matplotlib graphic in Sage cell serverhttp://ask.sagemath.org/question/9276/display-matplotlib-graphic-in-sage-cell-server/I'm writing a histogram interact in the Sage cell server at aleph.sagemath.org, and I can't get the graphic to display. The graphics display nicely within the interact in Sage 5.0 on my local installation, but won't appear in Sage 5.2 on the cell server. What can I do to display the graphic?
import matplotlib.pyplot as plt
@interact
def doit(title='Title',xlabel=('horizontal axis label','xlabel'),ylabel=('vertical axis label','ylabel'),numbins=slider(1,100,1,8,'number of bins'),data=input_box([358,311,172,190,369,298,308,330,223,187,371,419,296,298,258])):
plt.figure()
hp=plt.hist(data,bins=numbins)
plt.title(title)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.savefig(SAGE_TMP+'test2.png')
calc314Wed, 29 Aug 2012 17:34:11 -0500http://ask.sagemath.org/question/9276/Is there a simple way to plot an image in a notebook? I.e. the output of the imshow function in matplotlib...http://ask.sagemath.org/question/8526/is-there-a-simple-way-to-plot-an-image-in-a-notebook-ie-the-output-of-the-imshow-function-in-matplotlib/I have been wondering how to do something seemingly really simple, but seem to be missing something - sage allows users to do all kinds of fancy plotting in the notebook but I can't get it to display a 2d matrix as an image (matplotlib's imshow function).
I see that it is possible to call imshow and save the result to file, but I want to display the result in the notebook instead - did I miss something?
CheersnotsosageThu, 01 Dec 2011 08:36:21 -0600http://ask.sagemath.org/question/8526/Working with sage graphicshttp://ask.sagemath.org/question/8195/working-with-sage-graphics/I have written some code to plot some graphs (that is vertices and edges) and it has been suggested that I am being inefficient. I have say 50-100 primitives (consisting of lines and circles). At the moment I use to Graphics() to create an empty graphics object and then use + to add the primitives. Is there a better way to do this?
**Edit** The add_primitive() is one improvement. Here is a toy example
n = 10
g = Graphics()
for i in range(n):
for j in range(n):
g += line([(i,j),(i+1,j)])
g += line([(i,j),(i,j+1)])
g.show()
n = 10
g = Graphics()
for i in range(n):
for j in range(n):
g.add_primitive(line([(i,j),(i+1,j)]))
g.add_primitive(line([(i,j),(i,j+1)]))
g.show()
A second question is that I would also like to plot a formal linear combination of these graphs. At the moment I produce a list with a graph and the coefficients (via latex) alternating and then use graphics_array(). However I would prefer to group the primitives in a graph and in the latex and then scale these and place them myself.
**Edit** This is the code for my second question. The variable a is a formal linear sum (using CombinatorialFreeModule). The function circlepacking takes a graph and produces a graphics object.
r = a.monomial_coefficients()
pics = []
for f in r:
c = r[f]
if c == 1: lt = "$+$"
elif c == -1: lt = "$-$"
else: lt = "$+("+latex(c)+")$"
pics.append(text(lt,(0,0)))
pics.append(circlepacking(f,bv))
graphics_array(pics).show(axes=False,aspect_ratio=1)
I have looked at the matplotlib home page. I can see that there is a class Figure and so on. Should I be attempting to use these since I am working in sage?
I have used metapost and tikz in the past but not matlab.
P.S. I tried g=DiGraph() g.plot? and was directed to a file decorators.pyBWWTue, 28 Jun 2011 01:02:28 -0500http://ask.sagemath.org/question/8195/Can I convert a GraphicsArray object to a Graphics object?http://ask.sagemath.org/question/7870/can-i-convert-a-graphicsarray-object-to-a-graphics-object/This is related to the [Plot titles](http://ask.sagemath.org/question/248/plot-titles) question about adding titles to plots. I'd like to add a title--or any descriptive text--to an image created as a `GraphicsArray` object, but a `GraphicsArray` is not a `Graphics` object, so the easy idea of adding a `text` graphic at the bottom or top doesn't work. Moreover, other things one might want to to with a `GraphicsArray` image also don't work. Looking at the source code for `GraphicsArray`, it seems that the `._render()` function is doing all the hard work, and creates (but doesn't return) a matplotlib `Figure` object. Try as I might, I can't see how to get a `Graphics` object out.
(Note: I have been able to successfully use `convert` to add text outside of sage, as mentioned in response to the "Plot titles" question, but I'd like an internal way to do it, and I think this would be a generally useful thing to do anyway.)
Here's an extended example:
var('t')
A = [plot(sin(t+k*pi/4),(-pi,pi)) for k in range(8)]
graphics_array(A,3,3)
results in
![array of sine plots](/upfiles/12951061095513203.png)
I would be content (for now) to add a `text` graphics object to this image, but trying
graphics_array(A,3,3) + text('hello world',(0,0), axes=False)
results in a `TypeError`.
Now one can add the `text` graphic to the end of the list of objects for the array, but this has a couple of problems:
A = [plot(sin(t+k*pi/4),(-pi,pi)) for k in range(8)] + [text('hello world',(0,0), axes=False)]
graphics_array(A,3,3)
![graphics array including text object](/upfiles/12951066584996643.png)
Note that:
* `axes=False` in the `text` object has no effect -- one can turn off axes for *all* of the graphics in the array, but not for just one
* it would be nice if the text were centered, spanning the width of the image (especially for a long caption, which might be wider than the individual images in the array)
* placement of the text frame is awkward if there are 9 images to start with . . . I guess I could prepend the text object to the array . . .
----
UPDATE: There are now two tickets for issues here:
[#10656: GraphicsArray() should be a Graphics() object, or have functionality to return one](http://trac.sagemath.org/sage_trac/ticket/10656)
[#10657: options for items in a GraphicsArray() should be set independently](http://trac.sagemath.org/sage_trac/ticket/10657)nilesSat, 15 Jan 2011 04:03:30 -0600http://ask.sagemath.org/question/7870/