修改x和yrange? [英] Modifying x- and yrange?

查看:97
本文介绍了修改x和yrange?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下脚本:

set view map
set dgrid3d 2,2
splot "-" with points title "Data"
0 0 1
0 1 2
1 0 3
1 1 4
e

在图的四个角上绘制四个点.有没有办法扩大范围,以便在边框和圆点之间留一点边距?

plots four dots on the four corners of the diagram. Is there a way to extend the range, so that there is a small margin between the border and the dots?

我知道可以使用xrange或yrange命令来完成.但是我想说一种方式,在最外面的点和边界之间有一个10pt的空格.

I know that this can be accomplished using the xrange or yrange commands. But I'd rather like a way to say that a 10pt space is between the outer most point and the border.

像这样的解决方案:

  1. 获取当前的xmin和xmax值
  2. 使用返回的值进行一些数学运算,并相应地设置新的xmin和xmax值.

也很好.

感谢任何提示,链接和帮助!

Any hint, link and help is appreciated!

预先感谢

狼人

推荐答案

我发现以下几种可能使边框偏移的可能性:

I found the following possibility to offset the border by some factor:

set view map
set dgrid3d 2,2
splot "-" with points title "Data"
0 0 1
0 1 2
1 0 3
1 1 4
e
save set "Tmp.txt"
system("python SetRange.py Tmp.txt 1.1")
load "Tmp.txt"
splot "-" with points title "Data"
0 0 1
0 1 2
1 0 3
1 1 4
e

如您所见,gnuplot的状态保存在文件Tmp.txt中.在其他情况下,如果从文件中读取数据,则可以用replot替换低位splot命令.

As you can see, the state of gnuplot is saved in a file Tmp.txt. In other cases if the data is read from a file, the lower splot command could be replaced with a replot.

通过系统调用,您可以修改临时文件中xrange和yrange的条目.我用python脚本做到了这一点,因为我对awk ^^不太满意.

With the system call you can modify the entries of the xrange and yrange in the temp file. I did that with a python script, since I am not too good with awk^^.

import os
import sys

class Range(object):
    def __init__(self, line, factor):
        self.Line = line
        self.Factor = factor
        self.min, self.max = self._GetRange(self.Line)

        self.min_new, self.max_new = self._SetRange(self.min, self.max, self.Factor)

    def Write(self, file):
        Line_new = self.Line[0:self.Line.find("*")]
        Line_new = Line_new + str(self.min_new) + ":" + str(self.max_new)
        Line_new = Line_new + self.Line[self.Line.find("]") : self.Line.find("#")]

        file.write(Line_new + "\n")

    def _GetRange(self, line):
        min, max = (line[line.rfind("[") + 1 : line.rfind("]")]).split(":")
        return (float(min), float(max))

    def _SetRange(self, min, max, factor):
        dist_new = (max - min) * factor
        mean = (max - min) / 2 + min

        min_new = mean - dist_new / 2
        max_new = mean + dist_new / 2
        return (min_new, max_new)


if __name__ == '__main__':
    if not os.path.exists(sys.argv[1]):
        raise Exception("Cannot find file " + sys.argv[1])

    file = open(sys.argv[1])
    fileContents = file.read().split("\n")
    file.close()

    if len(sys.argv) > 2:
        factor = float(sys.argv[2])
    else:
        factor = 1.05

    for line in fileContents:
        if line.find("set xrange") != -1:
            xrange = Range(line, factor)
        elif line.find("set yrange") != -1:
            yrange = Range(line, factor)

    file = open(sys.argv[1], "w")
    xrange.Write(file)
    yrange.Write(file)
    file.close()

如果用awk可以用一种更短的方法来做到这一点,我会很高兴知道;)

If there is a shorter way to do that with awk, I'd be more than happy to know ;)

Cherio Woltan

Cherio Woltan

这篇关于修改x和yrange?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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