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.Sun, 08 Apr 2018 20:08:27 -0500Graphics not plotted in same plot?http://ask.sagemath.org/question/41925/graphics-not-plotted-in-same-plot/I'm trying to make a sierpinsky triangle recursively, and i can generate all the triangles (via 3 line segments), however when i go to show my list, the graphics print separately. I saw on the documentation there's a graphics_array, which seems useful, but there weren't many examples and my tinkering with it was pretty much useless, especially since the "adjoin" feature is not yet implemented.
Also tried passing the graphics object "some_lines" to get filled by the function, but it doesn't seem like it accesses the reference. Code attached, maybe you can see a way I can plot all the lines within one sum of graphics, as was my initial attempt:
def draw_tri(some_lines, endpts):
some_lines+=line([endpts[0], endpts[1]], color='blue')
some_lines+=line([endpts[0], endpts[2]], color='blue')
some_lines+=line([endpts[1], endpts[2]], color='blue')
return
def get_mid(x,y):
return (x+y)/2
def recurse_SG(some_lines, n, endpts):
#graphics_sum = graphics_array([line([endpts[0], endpts[1]], color='blue')],3, 1)
if(n==1):
#graphics_sum[i]=draw_tri(endpts)
draw_tri(some_lines, endpts)
else:
recurse_SG(some_lines, n-1, [endpts[0], (get_mid(endpts[0][0], endpts[1][0]), get_mid(endpts[0][1], endpts[1][1])), (get_mid(endpts[0][0], endpts[2][0]), get_mid(endpts[0][1], endpts[2][1]))])
recurse_SG(some_lines, n-1, [endpts[1], (get_mid(endpts[1][0], endpts[0][0]), get_mid(endpts[1][1], endpts[0][1])), (get_mid(endpts[1][0], endpts[2][0]), get_mid(endpts[1][1], endpts[2][1]))])
recurse_SG(some_lines, n-1, [endpts[2], (get_mid(endpts[2][0], endpts[0][0]), get_mid(endpts[2][1], endpts[0][1])), (get_mid(endpts[2][0], endpts[1][0]), get_mid(endpts[2][1], endpts[1][1]))])
show(some_lines, axes=false)Luther13Sun, 08 Apr 2018 20:08:27 -0500http://ask.sagemath.org/question/41925/Graphics array formattinghttp://ask.sagemath.org/question/33562/graphics-array-formatting/ I'm computing a number of plots (actually collections of 2d polygons) of roughly square aspect ratio, and would like to display them in a reasonable way:
* use two columns
* preserve order
* title each of them
* adjust the size to fill the width of my notebook, disregarding the height
First I displayed each graphics as it arrived, or combined bunches of them into `graphics_array` in order to show them. But my sage notebook (the classical one, not the IPython flavor) failed to preserve order in that case. So I feel that I have to build one big `graphics_array`.
But I've got trouble adjusting its width without specifying its height, and I don't know a suitable height up front. Most of the times if I specify one of the sizes too large, I end up with lots of empty space in one of the directions.
Furthermore, I didn't manage to title the individual graphics, since a `title` attribute to the `polygon2d` call remains without effect, while a `title` attribute to the `show` affects the whole plot and all the nested plots. Constructing an empty `Graphics(title="foo")` doesn't seem to work.
This is on sage 6.10.beta4, so things might have improved since then. If so, I haven't yet found the appropriate locations in the online documentation indicating how this changed.
If you want to try this out: I wanted to format the output of [this code](https://gist.github.com/gagern/e9606b3f12d53ff92c4541e1e7b51d6d) but using two columns and a varying number of rows for each *n*.MvGThu, 26 May 2016 18:41:11 -0500http://ask.sagemath.org/question/33562/Why does graph plotting crop so aggressively, and what is a work-around?http://ask.sagemath.org/question/8016/why-does-graph-plotting-crop-so-aggressively-and-what-is-a-work-around/Surely, the Sage community is aware of this bug. For example, there is [this ticket](http://trac.sagemath.org/sage_trac/ticket/7299), in which the problem is supposed to be fixed. But it's not!
A patch is described: in `sage/graphs/graph_plot.py` we can add the line(?)
> `G._extra_kwds['axes_pad']=.05 `
Am I to change this value in order to fix this over-zealous cropping behavior? No matter what I do, in this regard, I still end up with graph vertices partially cut off.
What's the easy work-around? I would like to be able to plot `graphics_array` objects with several graphs (with their vertices clearly shown!).
(http://trac.sagemath.org/sage_trac/ticket/7299)Sammy BlackMon, 21 Mar 2011 08:00:06 -0500http://ask.sagemath.org/question/8016/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/graphics_array argumentshttp://ask.sagemath.org/question/7828/graphics_array-arguments/For some reason, not all the arguments for graphics objects are transferred to graphics_array. For example, this code shows the axes and frames even though it is disabled in the individual graphics objects:
<pre>graphics_array([matrix_plot([[0,1,2]], frame=False, axes=False), matrix_plot([[0,1,2]], frame=False, axes=False)])</pre>
Is this a bug, and is there a way around this?Eviatar BachMon, 20 Dec 2010 13:43:28 -0600http://ask.sagemath.org/question/7828/Tables of graphics?http://ask.sagemath.org/question/7519/tables-of-graphics/I recall seeing a function that would allow one to make a table (or a series) of graphics. For example, if I wanted to display 10 plots in a series, how would I do this?
Thanks in advance.Eviatar BachFri, 10 Dec 2010 17:37:13 -0600http://ask.sagemath.org/question/7519/