Ask Your Question

Revision history [back]

Can I get a Graphics object from GraphicsArray?

This is related to the 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:

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

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

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 . . .

Can I get a Graphics object from GraphicsArray?

This is related to the 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

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

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 . . .
click to hide/show revision 3
fixed title to be more accurate

Can I get convert a GraphicsArray object to a Graphics object from GraphicsArray?object?

This is related to the 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

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

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 . . .

Can I convert a GraphicsArray object to a Graphics object?

This is related to the 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

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

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

#10657: options for items in a GraphicsArray() should be set independently