Multiple plots in one (pdf) file?

1,341 views
Skip to first unread message

G. Patrick Mauroy

unread,
Feb 7, 2014, 11:35:57 AM2/7/14
to julia...@googlegroups.com
Just starting taking a look at Julia.  I have seen examples on how to send a plot to a file.  But I have not stumbled upon one example as yet to export multiple plots to the same file, say pdf.
Can someone please point me in the right direction?

# R example of what I would like to do.
x = 1:3
pdf(file = "plotR.pdf")
plot(x = x, y = x + 3)
plot(x = x, y = 2 * x + 1)
dev.off()

# My first Julia attempt.
using Gadfly
x = [1,2,3]
plot1 = plot(x = x, y = x + 3)
plot2 = plot(x = x, y = 2 * x + 1)
draw(PDF("plotJ.pdf", 6inch, 3inch), plot1)
draw(PDF("plotJ.pdf", 6inch, 3inch), plot2)

Pb: plot2 overrides plot1, so only plot2 in plotJ.pdf.

To be clear, in this example, I want plot1 & plot2 in two distinct plots/pages -- as opposed to merge both graphs into one plot.

Thanks.

Daniel Jones

unread,
Feb 7, 2014, 12:02:28 PM2/7/14
to julia...@googlegroups.com
There's not a way to put them on separate pdf pages, but you can stack them and output them to the same pdf like:

using Gadfly
x = [1,2,3]
plot1 = plot(x = x, y = x + 3)
plot2 = plot(x = x, y = 2 * x + 1)
draw(PDF("plotJ.pdf", 6inch, 6inch), vstack(plot1, plot2))

G. Patrick Mauroy

unread,
Feb 7, 2014, 12:41:21 PM2/7/14
to julia...@googlegroups.com
Ouch!
In my opinion, this may be a major stumbling block for Julia adoption.
I, and I am sure many, find it typical routine to load data, crunch, make a variety of graphical views (sometimes very many), export them to files in an organized way for analysis and sharing a story line.
With many such plots, one file per plot could become quickly messy, harder to manage.

I suppose then a workaround would be to organize plots in sub-directories, as PNG pictures for ease of scrolling through them.  Perhaps not that bad after all thinking about it.  I suppose I can live with that.

I still believe it would be a good idea if support to have multiple plots in one pdf would be added somehow, very handy!

Thanks for the info, it saves me some search time.

John Myles White

unread,
Feb 7, 2014, 12:42:49 PM2/7/14
to julia...@googlegroups.com
Isn't the behavior Daniel described how ggplot2 works? Certainly it's how ggsave works.

 -- John

Mike Nolta

unread,
Feb 7, 2014, 12:57:58 PM2/7/14
to julia...@googlegroups.com
You can do this in Winston:

file([plot1,plot2], "plots.pdf")

-Mike

Steven G. Johnson

unread,
Feb 7, 2014, 1:21:02 PM2/7/14
to julia...@googlegroups.com


On Friday, February 7, 2014 12:41:21 PM UTC-5, G. Patrick Mauroy wrote:
In my opinion, this may be a major stumbling block for Julia adoption.
I, and I am sure many, find it typical routine to load data, crunch, make a variety of graphical views (sometimes very many), export them to files in an organized way for analysis and sharing a story line.
With many such plots, one file per plot could become quickly messy, harder to manage.

This is precisely what IJulia (IPython) notebooks give you: a single file, including code and plots and other output, including descriptions, headings etcetera, in order to share an analytical story.   Much better than PDF because other people can open the notebook and run their own computations by modifying yours!

That being said, with PyPlot (i.e. matplotlib), you can make a single figure (exportable to a file) containing multiple sub-plots using the subplot command.  e.g. 2 side-by-side plots via:

    subplot(1,2,1)
    plot(rand(10))
    subplot(1,2,2)
    plot(rand(20))
    savefig("twoplots.pdf")

--SGJ
 

Peter Simon

unread,
Feb 8, 2014, 4:02:02 PM2/8/14
to julia...@googlegroups.com
I wrote the (admittedly primitive) attached savefigppt() function to save multiple PyPlot images to a Powerpoint-compatible .pptx file (works on both Windows and Linux).  When adding an image to a file, if the file already exists then the image will be added to a new page appended at the end.  The Powerpoint file can then be converted to other formats, presumably including PDF.  Note that you must have installed the Julia packages PyCall and PyPlot, and the Python package python-pptx (see https://python-pptx.readthedocs.org/en/latest).

--Peter
Saveppt.jl
Reply all
Reply to author
Forward
0 new messages