如何使用 Gnuplot 创建多页 PDF 文件?

发布于 2024-10-05 19:13:18 字数 509 浏览 1 评论 0原文

我通过 ruby-gnuplot 在 Mac 上使用 Gnuplot 绘制了十几张图。如果我重新运行我的 ruby​​ 脚本,那么带有绘图的打开窗口的数量就会增加一倍。如果我可以将所有这些绘图输出到在预览中打开的 PDF 中,那么该文件将在每次重新运行后自动更新,并且我不需要费心关闭众多窗口。

目前,我只能通过每个 PDF 文件一个图来实现这一点:

Gnuplot.open do |gp|
  Gnuplot::Plot.new(gp) do |plot|
    plot.arbitrary_lines << "set terminal pdf \n set output 'figures.pdf'"
    # ...
  end
end

How can I make a single PDF with my all pictures by Gnuplot?

I make a dozen of plots with Gnuplot on Mac via ruby-gnuplot. If I re-run my ruby script, then the number of open windows with the plots doubles. If I could just output all these plots in a PDF opened in Preview, then the file would be automatically updated after every re-run and I don't need to bother closing the numerous windows.

Currently I can achieve this only with one plot per PDF-file:

Gnuplot.open do |gp|
  Gnuplot::Plot.new(gp) do |plot|
    plot.arbitrary_lines << "set terminal pdf \n set output 'figures.pdf'"
    # ...
  end
end

How can I make a single PDF with all my figures by Gnuplot?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

·深蓝 2024-10-12 19:13:18

嗯,至少在 UN*x 的 gnuplot 上,postscript 和 PDF 的多页输出始终是默认设置 - 只要您不更改终端类型也不重新分配输出文件,您绘制的所有内容都会在新页面上结束。

也就是说,您这样做了:

set terminal pdf
set output "multipageplot.pdf"
plot x, x*x
plot sin(x), cos(x)
set output ""

您最终会在 PDF 文件中得到两页,其中一页包含直线/抛物线,另一页包含正弦/余弦。

澄清一下:重要的是按顺序发出所有 plot 命令,而不更改输出文件或更改终端类型。 Gnuplot 不会附加到现有的 PDF 文件。

Hmm, at least on gnuplot for UN*x, multipage output for postscript and PDF always was the default - as long as you don't either change the terminal type nor reassign the output file, everything you plot ends up on a new page.

I.e. you do:

set terminal pdf
set output "multipageplot.pdf"
plot x, x*x
plot sin(x), cos(x)
set output ""

and you end up with two pages in the PDF file, one containing line/parabola, the other sine/cosine.

To clarify: The important thing is to issue all the plot commands in sequence, without changing the output file nor changing the terminal type. Gnuplot won't append to an existing PDF file.

浪漫之都 2024-10-12 19:13:18

我使用 ruby​​-gnuplot 制作了数千个绘图,并使用名为 prawn 的 gem 将它们编译成 pdf。以下是使用 prawn 的代码片段,其中包括一些有用的功能:

require 'prawn'

def create_pdf
  toy_catalogue = @toy_catalogue
  full_output_filename ||= "#{output_path}/#{pre-specified_filename_string}"
  Prawn::Document.generate(full_output_filename, :page_layout => :portrait, :margin => 5, :skip_page_creation => false, :page_size => [595, 1000]) do
    toy_catalogue.each do |toy|
      start_new_page

      image toy[:plan_view], :at => [0,900], :width => 580

      image toy[:front_view], :at => [0, 500], :width => 585

      font_size(20) { draw_text toy[:name], :at => [5, 920] }

      draw_text "production_date = #{toy[:date]}", :at => [420, 930]
    end
  end
end

这应该很容易适应您的目的。

I make thousands of plots with ruby-gnuplot and use a gem called prawn to compile them into a pdf. The following is a code snippet using prawn, that includes some useful features:

require 'prawn'

def create_pdf
  toy_catalogue = @toy_catalogue
  full_output_filename ||= "#{output_path}/#{pre-specified_filename_string}"
  Prawn::Document.generate(full_output_filename, :page_layout => :portrait, :margin => 5, :skip_page_creation => false, :page_size => [595, 1000]) do
    toy_catalogue.each do |toy|
      start_new_page

      image toy[:plan_view], :at => [0,900], :width => 580

      image toy[:front_view], :at => [0, 500], :width => 585

      font_size(20) { draw_text toy[:name], :at => [5, 920] }

      draw_text "production_date = #{toy[:date]}", :at => [420, 930]
    end
  end
end

That should be easy enough to adapt to your purposes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文