## Graphics Array in Sage(math)

August 12, 2010 by doxdrum

For a publication I was working on, I plotted functions in PDF format. However, the journal ask me to handle them in EPS format.

“What’s the point?” you might ask. Well, since I installed Lucid Lynx (a clean installation), the files of those graphic were gone… Fool of me, you will say, but really, I never thought that this days journals DO NOT accept PDF files!!!!

Who cares! to the point.

First I tried with the convert command

`for i in *.pdf; do convert $i $(echo $i| sed -e s/pdf/eps/g); done`

It did the job, but the quality of the plots was compromised.

Then, I move to Sage(math), and re-discover the function ‘graphics_array’, and try this,

p1 = plot(Vn(x, 1, 3), (x,-5,5), color='black', thickness=2)
p1 += plot(Vp(x, 1, 3), (x,-5,5), color='black', thickness=2, linestyle='-.', \
axes_labels=[r'$\xi^\prime', r'$V_{qm}(\xi^\prime)$'], fontsize=17)
p2 = plot(Vn(x, 3, 3), (x,-5,5), color='black', thickness=2)
p2 += plot(Vp(x, 3, 3), (x,-5,5), color='black', thickness=2, linestyle='-.', \
axes_labels=[r'$\xi^\prime$',r''], fontsize=17)
p3 = plot(Vn(x, 5, 3), (x,-5,5), color='black', thickness=2)
p3 += plot(Vp(x, 5, 3), (x,-5,5), color='black', thickness=2, linestyle='-.', \
axes_labels=[r'$\xi^\prime$',r''], fontsize=17)

… a little explanation?! p1, p2 and p3 are the graphics I’d like put into an array, each of them contain 2 plots (both black because otherwise they’ll make me pay an incredible amount of money… crazy people!), and them try the graphics_array,

ga = graphics_array([p1, p2, p3])
ga.show(frame=True, axes=False, figsize=[12,8])

and obtain something like this,

First try with graphics_array

Yeah babe!!!… What???!!! It’s not all right! What happened with the axis labels, the font size, and so on?

**Second try: **let’s see if the plots are working one by one

`p1`

This is the right p1

`p2`

The right p2

`p3`

The right p3

The are alright! So, What happened? Let me run again the graphics_array commands

ga = graphics_array([p1, p2, p3])
ga.show(frame=True, axes=False, figsize=[12,8])

What did I get?…

The final result was as I wanted to be!

MORAL: Make Sage(math) show you the plot, one by one, before make them into an array!

Yeah… I almost forgot it!

My goal was to save it as an EPS file, so after getting the looked graph, the command is

ga.save(frame=True, axes=False, figsize=[12,8], \
filename='/path/to/directory/name-of-plot.eps')

**Cya all!**

### Like this:

Like Loading...

*Related*

on August 12, 2010 at 11:53 am |schillyIs it a bug that you have to execute the individual plots first?

Anyways, litte hint, you can combine common parameters in a variable. That helps to control them at one central point (i.e. plot color or something else)

sage: plotopts = { ‘color’: ‘black’, ‘thickness’: 10 }

sage: p1 = plot(sin, (-6,6), **plotopts)

sage: p2 = plot(cos, (3,12), linestyle=’-.’, **plotopts)

sage: show(p1+p2)

on August 12, 2010 at 12:13 pm |doxdrumThx Schilly… wonderful advise!,😉

on August 27, 2011 at 3:23 am |Leon SwinkelsThanks, this post was very usefull.

I use sage a lot to plot Graphs, and it seems that graph plotting is done somewhat at random. So it really helps to plot ( and seemingly finalize them first ) before entering them into a graphics array.