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.Mon, 15 Apr 2019 16:25:48 -0500help with graphics_array magic, pleasehttp://ask.sagemath.org/question/46199/help-with-graphics_array-magic-please/ following [Juanjo's](https://ask.sagemath.org/users/25859/juanjo/) [advice](https://ask.sagemath.org/question/46188/same-ymin-and-ymax-accross-many-seperate-plots/), I created a graphics_array.
Because i want to do a pairwise comparison with my graphs, i reordered them (with the zip). Now i have a 2xn array, with all the same x- and y-axis lables and also the same leged_labels, so I want to make it nice and put the legend_lable just in the bottom right plot and the left row gets the y-axis lable and the bottom row the x-axis lable.
here is my attempt at doing that.
l = []
k=1.0
p=plot(k*sin(x),(x,-pi,pi),axes_labels=['','$\\varphi$ in [V]'])
l.append(p)
k+=1
p=plot(k*sin(x),(x,-pi,pi))
l.append(p)
k+=1
p=plot(k*sin(x),(x,-pi,pi),axes_labels=['$z_c$ in [m]','$\\varphi$ in [V]'])
l.append(p)
k+=1
p=plot(k*sin(x),(x,-pi,pi), legend_label=['text'],axes_labels=['$z_c$ in [m]',''])
l.append(p)
ym = 1e+20
yM = 1e-20
for i in range(len(l)):
bounds = l[i].get_minmax_data()
ym = min(ym, bounds["ymin"])
yM = max(yM, bounds["ymax"])
gpairs = list(zip(l[::2], l[1::2]))
pic=graphics_array(gpairs) # each plot uses its own vertical scale
graphics_array(gpairs).show(ymin=ym,ymax=yM, frame=True,figsize=[4,8],gridlines=True,typeset='latex',) # same scale for all plots
pic.save('pairwise-comp
This is the pic i get: ![image description](/upfiles/15553631452996794.png)
The labels on the y-axes are gone. only the bottom right has the x-axis lable. and the legend_lable is double in the bottom right.
I have not tried to decorate the rows with text left to the graphs and columns above the graphs.
is what i try to do feasable? or how can i do those things in LaTeX, outside sage? I dont see how i could do the ymin,ymax scaling in latex, but i could do that manually in sage and go back to individual graphs, if all else fails.
stockh0lmMon, 15 Apr 2019 16:25:48 -0500http://ask.sagemath.org/question/46199/Graphics 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/connecting plots by lineshttp://ask.sagemath.org/question/38845/connecting-plots-by-lines/There are 2 plots in a graphics_array (e.g. sin and cos). How do I "connect" these plots with connecting lines (e.g. a dashed line at angle=pi)?Chris_Mon, 18 Sep 2017 08:21:55 -0500http://ask.sagemath.org/question/38845/Graphics array without tickshttp://ask.sagemath.org/question/38271/graphics-array-without-ticks/Hello,
how can I create a graphics array consisting of 4 graphs without ticks? I tried this:
p1=plot(EllipticCurve([0,0,0,-1,2]), color='red', ticks=[[],[]])
p2=plot(EllipticCurve([0,0,0,1,-1]), color='red', ymin=-3, ymax=3, ticks=[[],[]])
p3=plot(EllipticCurve([0,0,0,-1,-1]), color='red', ymin=-4, ymax=4, ticks=[[],[]])
graphics_array(((p1,p2),(p3,p1)))
But it doesn't work. Only the last graphic is without ticks. Thank you very much! :)test1234Sat, 15 Jul 2017 02:16:53 -0500http://ask.sagemath.org/question/38271/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/Multiple 3D plots in one panel -> graphics_array and 3D?http://ask.sagemath.org/question/7896/multiple-3d-plots-in-one-panel-graphics_array-and-3d/Hello,
I am new to Sage and trying to learn as quickly as I can (I am a former Maple user).
I have been searching the reference docs, google group and the Net to find a way for putting multiple 3D plots in one panel, in a similar way as with graphics_array for 2D plots. Actually, I have not initially seen that graphics_array was only for 2D plots, and spent some time trying to make it work with my plots. When trying this, I was getting "raise TypeError, "every element of array must be a Graphics object" since the elements of my array are of type <class 'sage.plot.plot3d.base.Graphics3dGroup'>.
So, may question is the following: is there any trick that would allow me a to build a panel of 3D plots in a similar way as with graphics_array?
I would be very grateful if you could give me some hints on this problem.
Regards,
MuratmyildiTue, 25 Jan 2011 09:58:40 -0600http://ask.sagemath.org/question/7896/Legend appears twicehttp://ask.sagemath.org/question/24699/legend-appears-twice/ I have some problem with the legend, if I use the function **graphics_array** the entries of the legend box of the second plot appear twice. For example:
f(x) = sin(x)
g(x) = sin(2*x)
p1 = plot(f,(-2*pi,2*pi), legend_label="f")
p2 = plot(g,(-2*pi,2*pi), legend_label="g")
graphics_array((p1,p2))
What I am doing wrong, or how can I fix it? Thanks in advance petresThu, 30 Oct 2014 05:34:38 -0500http://ask.sagemath.org/question/24699/axis labels / title on graphs in graphics_arrayhttp://ask.sagemath.org/question/24597/axis-labels-title-on-graphs-in-graphics_array/I'm putting four graphs together in a `graphics_array`. I'm finding that only the axis labels and title on the last graph in the `graphics_array` command appear. I would like to have them appear on all 4 graphs. Here is a simplified example:
p1=plot(x^2,(x,-2,2),axes_labels=['x1','y1'])
p2=plot(x^2-1,(x,-2,2),axes_labels=['x2','y2'])
p3=plot(x^2+1,(x,-2,2),axes_labels=['x3','y3'])
p4=plot(x^3,(x,-2,2),axes_labels=['x4','y4'])
g=graphics_array([[p1,p2],[p3,p4]])
show(g)
![image description](https://sagecell.sagemath.org/kernel/9e61ebee-fd6b-4014-828a-02857aa27998/files/sage0.png)calc314Thu, 23 Oct 2014 07:38:52 -0500http://ask.sagemath.org/question/24597/Making a graphics array with different numbers of plots in each rowhttp://ask.sagemath.org/question/10593/making-a-graphics-array-with-different-numbers-of-plots-in-each-row/I'm trying to create a graphics array with one plot in the first row and three in the second. Here's a minimal example:
p0 = plot(x)
p1 = plot(x^2)
p2 = plot(x^3)
g = graphics_array([[p0], [p1, p2]])
g.show()
When executing this, I get each plot separately and then an error message reading, "TypeError: array (=[[], [, ]]) must be a list of lists of Graphics objects". What am I doing wrong? How is what I have not a list of lists of Graphics objects?jaiaSun, 06 Oct 2013 13:04:30 -0500http://ask.sagemath.org/question/10593/graph formatting issue in graphics arrayhttp://ask.sagemath.org/question/9782/graph-formatting-issue-in-graphics-array/Hi,
I would like to layout my set of phase plots in an array. However I am having issues with getting font size correct, and axes labels to show up on all the graphs. Also my distance/velocity/acceleration phase plots are showing up as not being an graphic so I am unable to add them to the array.
code:
xy = zip(result[:,0],result[:,2])
uv = zip(result[:,1],result[:,3])
dudv = zip(udott,vdott)
tx = zip(ts,result[:,0])
ty = zip(ts,result[:,2])
tu = zip(ts,result[:,1])
tv = zip(ts,result[:,3])
tudot = zip(ts,udott)
tvdot = zip(ts,vdott)
xu = zip(result[:,0],result[:,1])
yv = zip(result[:,2],result[:,3])
udu = zip(result[:,1],udott)
vdv = zip(result[:,3],vdott)
xdu = zip(result[:,0],udott)
ydv = zip(result[:,2],vdott)
xudu = zip(result[:,0],result[:,1],udott)
yvdv = zip(result[:,2],result[:,3],vdott)
pltx = line(tx, color = 'red', thickness = 0.05)
plty = line(ty, color = 'orange', thickness = 0.05)
pltxy = line(xy, color = 'yellow', thickness = 0.05)
pltu = line(tu, color = 'green', thickness = 0.05)
pltv = line(tv, color = 'blue', thickness = 0.05)
pltuv = line(uv, color = 'indigo', thickness = 0.05)
pltudot = line(tudot, color = 'violet', thickness = 0.05)
pltvdot = line(tvdot, color = 'red', thickness = 0.05)
pltdudv = line(dudv, color = 'orange', thickness = 0.05)
pltxudu = line(xudu, color = 'yellow', thickness = 0.5)
pltyvdv = line(yvdv, color = 'green', thickness = 0.5)
show(graphics_array([pltx,plty,pltxy,pltu,pltv,pltuv,pltudot,pltvdot,pltdudv],3,3), frame = True, axes = False, dpi = 200)
eric.c.kangasThu, 07 Feb 2013 02:23:34 -0600http://ask.sagemath.org/question/9782/workaround for graphics_array needing prior show?http://ask.sagemath.org/question/9593/workaround-for-graphics_array-needing-prior-show/I'm trying to use graphics_array to show a list of four simple plots. when I create the plots and display them straightaway in the graphics_array() it messes up the axis labeling and so on. I discovered via google that you can workaround that by first calling show() or save() on each of the graphs (I guess that finalizes their layout etc), and then call graphics array to combine them. But this results in each of the charts being shown individually before being shown in an array, which defeats the purpose.
The closest I've found is calling save('foo.pdf') on each of the charts, since it doesn't know how to display a PDF file you only get a link to 'foo.pdf'. I guess what I'd really like is save(filename, display=False) or something? (Of course ultimately I'd like graphics_array() to do the right thing in the first place and prepare each chart individually before compositing them)
Any ideas?PatrickSurryFri, 30 Nov 2012 06:52:41 -0600http://ask.sagemath.org/question/9593/How to control layouts of individual plots within a graphics_array?http://ask.sagemath.org/question/8156/how-to-control-layouts-of-individual-plots-within-a-graphics_array/I am trying to plot two graphics side-by side from with an '@interact' function within the Sage notebook.
I define my graphics array and render it with the appropriate size as follows:
myGraphicsArray = graphics_array([myPlot1, myPlot2])
myGraphicsArray.show(figsize=[14,5])
This is fine, but how can I control features of the individual plots separately? (e.g. axis range, aspect ratio, maybe even relative sizes of the two plots etc.)
For now I have found a kludge workaround, which is to .show() the individual plots first of all (making them very small) within which I set the relevant layout parameters as follows:
myPlot1.show(ymin=-40,ymax=10,figsize=0.1) # note small figsize
myPlot2.show(xmin=-axisMax, xmax=axisMax, ymin=-axisMax, ymax=axisMax, aspect_ratio=1, figsize=0.1) # note small figsize
This is not ideal, as it plots them (albeit small) when I didn't really want to. But at least it allows me to control their respective layouts when they later appear within the graphics_array.
But is there a better way to do this?
deebs67Thu, 09 Jun 2011 03:42:41 -0500http://ask.sagemath.org/question/8156/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/