Gnuplot多图:创建更复杂布局的便捷方法 [英] Gnuplot multiplot: Convenient method for creating more complex layouts

查看:77
本文介绍了Gnuplot多图:创建更复杂布局的便捷方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过以下方式使用 gnuplot 放置多个图:

I want to place several plots with gnuplot in following way:

 +------------------------+
 |plot1                   |
 |                        |
 +------------------------+
 +----------++------------+
 |plot2     ||plot3       |
 |          ||            |
 +----------++------------+
 +----------++------------+
 |plot4     ||plot5       |
 |          ||            |
 +----------++------------+

可以通过set multiplot layout n,m实现简单的nxm布局(有关以下内容,请参见 demos 插图在官方网站上.

Simple nxm layouts can be achieved via set multiplot layout n,m (see these demos for illustration on the official website).

matplotlib 提供了更高级的可能性,如文档所示:在gnuplot中,我已经使用set originset size来实现这一点.但是,这很麻烦,并且当您发现以后要更改布局时,需要重新计算尺寸和位置.

Within gnuplot I have used set origin and set size to achieve this. However, it is rather cumbersome and requires recalculation of sizes and positions when you notice you want to change the layout afterwards.

备注1: 通常,将边距设置为固定大小以达到正确的绘图大小也很有用.通过改变xlabel等自动计算,否则将很难获得正确的布局.

Remark 1: Often it is also useful to set the margins to fixed sizes to achieve the correct plot sizes. The auto-calculation by varying xlabels and so on would make it otherwise even more difficult to achieve the correct layout.

备注2: gnuplot代替了origin/size,它提供了另一种使用set [lrbt]margin <> at screen的可能性,它可以设置图边框.用户必须确保标题和标签有足够的空间(请参阅 demo ).仍然不是一个完美的解决方案,但有时更方便.

Remark 2: Instead of origin/size gnuplot offers another possibility using set [lrbt]margin <> at screen which sets plot borders. The user has to make sure that there is enough space for titles and labels (see demo). Still not a perfect solution but sometimes more convenient.

是否有可能我不知道或者是否存在用于创建布局的工具?

Is there a possibility that I am not aware of or does possibly a tool exist to create layouts?

推荐答案

您可以从matplotlib获取几何.创建两个文件 subplot2grid2gnuplot.py subplot2grid.gp . test.gp 是用法示例.

You can get geometry from matplotlib. Create two file subplot2grid2gnuplot.py and subplot2grid.gp. test.gp is an example of usage.

subplot2grid2gnuplot.py

import matplotlib.pyplot as plt
import sys

if len(sys.argv)<6:
    sys.stderr.write("ERROR: subplot2grid2gnuplot.py needs 6 arguments\n")
    sys.exit(1)

shape = (int(float(sys.argv[1])), int(float(sys.argv[2])))
loc   = (int(float(sys.argv[3])), int(float(sys.argv[4])))
colspan = int(float(sys.argv[5]))
rowspan = int(float(sys.argv[6]))

ax = plt.subplot2grid(shape, loc, colspan, rowspan)
print "%f %f %f %f" % ax._position.bounds

subplot2grid.gp

# Return origin and size of the subplot
# Usage:
# call subplot2grid.gp shape1 shape1 loc1 loc2 colspan rowspan
# Sets:
# or1, or2, size1, size2

aux_fun__(shape1, shape2, loc1, loc2, colspan, rowspan) = \
   system(sprintf("python subplot2grid2gnuplot.py  %i %i %i %i %i %i %i", shape1, shape2, loc1, loc2, colspan, rowspan))

aux_string__= aux_fun__($0, $1, $2, $3, $4, $5)
or1=word(aux_string__,1)
or2=word(aux_string__,2)
size1=word(aux_string__,3)
size2=word(aux_string__,4)

test.gp

unset xtics
unset ytics

set multiplot

call "subplot2grid.gp" 3 3 0 0 1 3
set size size1, size2
set origin or1, or2
plot sin(x)

call "subplot2grid.gp" 3 3 1 0 1 2
set size size1, size2
set origin or1, or2
plot sin(x)

call "subplot2grid.gp" 3 3 1 2 2 1
set size size1, size2
set origin or1, or2
plot sin(x)

call "subplot2grid.gp" 3 3 2 0 1 1
set size size1, size2
set origin or1, or2
plot sin(x)

call "subplot2grid.gp" 3 3 2 1 1 1
set size size1, size2
set origin or1, or2
plot sin(x)

unset multiplot

这篇关于Gnuplot多图:创建更复杂布局的便捷方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆