gnuplot的坐标系统之间的转换 [英] Conversion between gnuplot's coordinates systems

查看:194
本文介绍了gnuplot的坐标系统之间的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多图设置中是否可以对齐不同图的角?

Is there a way to align corners of different plots in a multiplot setup?

是否可以将axis坐标转换为screen坐标?

Is there a way to convert axis coordinates to screen coordinates?

我正在尝试使用gnuplot布局一个非常复杂的画布.为了实现我想要的,我需要彼此精确地堆叠不同的图.

I'm trying to layout a quite complicated canvas with gnuplot. To achieve what I want, I need to stack different plots on each other exactly.

我做了类似的事情:

reset;
set samples 20;
set xrange [-pi:pi]; set yrange [-2:1];
set xlabel "x"; set ylabel "y";
unset key

set multiplot;
plot cos(x) w lp;
plot 2*cos(x+pi) w lp;
unset multiplot;

但是,某些组件(如标签,标记和边框)被绘制了两次.然后,当我使用cairolatex终端执行此操作时,结果似乎不像我不叠加绘图一样.

However, some components like the label, tics and borders are drawn twice. Then, when I do this with the cairolatex terminal the result is not as clear as if I don't stack plots.

因此,我想在第一个绘图中绘制这些组件,然后为随后的那些未设置标签,标记和边框,如下面的代码片段所示:

Thus, I would like to draw these components for the first plot and then unset labels, tics and borders for the subsequent ones as shown in the snippet below:

set multiplot;
plot cos(x) w lp;

set border ls 4; # Just to distinguish it
unset xlabel; unset ylabel;
unset tics;
plot 2*cos(x+pi) w lp;
unset multiplot;

这将生成一个图像,其中下一个图未与第一个图对齐(在左侧和底部),因为标签和抽号没有占用空间.

This generate an image where the next plots are not aligned (on left and bottom) with the first one, as no space is taken by the labels and tics.

要解决此问题,我需要手动设置下一个图的原点和大小.左下角必须对齐.

To address this issue, I need to set the origin and size of the next plots manually. The bottom left corners must be aligned.

从gnuplot文档中,可以使用以下方法获取(X,Y) axis坐标的screen坐标:

From the gnuplot documentation, it is possible the get the screen coordinated of an (X,Y) axis coordinate using:

GRAPH_X = (X - GPVAL_X_MIN) / (GPVAL_X_MAX - GPVAL_X_MIN)
GRAPH_Y = (Y - GPVAL_Y_MIN) / (GPVAL_Y_MAX - GPVAL_Y_MIN)
SCREEN_X = GPVAL_TERM_XMIN + GRAPH_X * (GPVAL_TERM_XMAX - GPVAL_TERM_XMIN)
SCREEN_Y = GPVAL_TERM_YMIN + GRAPH_Y * (GPVAL_TERM_YMAX - GPVAL_TERM_YMIN)
FRAC_X = SCREEN_X * GPVAL_TERM_SCALE / GPVAL_TERM_XSIZE
FRAC_Y = SCREEN_Y * GPVAL_TERM_SCALE / GPVAL_TERM_YSIZE

在尝试对齐左下角(X,Y) == (GPVAL_X_MIN, GPVAL_Y_MIN)时.因此,GRAPH_* = 0SCREEN_(*) = GPVAL_TERM_\1MIN.因此:

As we are trying to align the bottom left corner, (X,Y) == (GPVAL_X_MIN, GPVAL_Y_MIN). Thus, GRAPH_* = 0 and SCREEN_(*) = GPVAL_TERM_\1MIN. Thus:

# Multiply by 1.0 to promote variables to floats
FRAC_X = 1.0 * GPVAL_TERM_XMIN * GPVAL_TERM_SCALE / GPVAL_TERM_XSIZE
FRAC_Y = 1.0 * GPVAL_TERM_YMIN * GPVAL_TERM_SCALE / GPVAL_TERM_YSIZE

结果片段:

set multiplot;
plot cos(x) w lp;

FRAC_X = 1.0 * GPVAL_TERM_XMIN * GPVAL_TERM_SCALE / GPVAL_TERM_XSIZE;
FRAC_Y = 1.0 * GPVAL_TERM_YMIN * GPVAL_TERM_SCALE / GPVAL_TERM_YSIZE;
set origin FRAC_X, FRAC_Y;

set border ls 4; # Just to distinguish it
unset xlabel; unset ylabel;
unset tics;
plot 2*cos(x+pi) w lp;
unset multiplot;

但是正如您所看到的,结果情节并没有改善...

But as you can see, resulting plot is not better...

顺便说一句,我没有找到如何定义size来对齐右上角.

By the way, I did not find how to define the size to align the top right corners.

原点计算有什么问题?如何也对齐右上角?

What is wrong with the origin computation? How to align top right corner as well?

亲切的问候,

亚历克西斯.

推荐答案

您可以按如下所示固定边距以保持自动大小不变(另请参见https://stackoverflow.com/a/19132068/2604213 ):

You can fix the margins to keep the automatic size after the first plot as follows (see also https://stackoverflow.com/a/19132068/2604213):

fix_margins = 'set margins '.\
    'screen GPVAL_TERM_SCALE * GPVAL_TERM_XMIN/(1.0*GPVAL_TERM_XSIZE), '.\
    'screen GPVAL_TERM_SCALE * GPVAL_TERM_XMAX/(1.0*GPVAL_TERM_XSIZE), '.\
    'screen GPVAL_TERM_SCALE * GPVAL_TERM_YMIN/(1.0*GPVAL_TERM_YSIZE), '.\
    'screen GPVAL_TERM_SCALE * GPVAL_TERM_YMAX/(1.0*GPVAL_TERM_YSIZE)'

set samples 20
set xrange [-pi:pi]; set yrange [-2:1]
set xlabel "x"; set ylabel "y"
unset key

set multiplot
plot cos(x) w lp
eval(fix_margins)
unset tics; unset xlabel; unset ylabel
plot 2*cos(x+pi) w lp
unset multiplot

这篇关于gnuplot的坐标系统之间的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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