How to access Gnuplot's (auto)range values and modify them to add some margin?

一曲冷凌霜 提交于 2019-12-20 10:12:02

问题


Using the standard plot command, I get, what I want except that the yrange is set automatically from (eg) 275 to 300.

Unfortunately, I have several data points with y-coordinate 300, such that they are not visible (due to border lines, etc.).

So, is there any way to set the maximum yrange such that it is always the maximum data plus e.g. 5 units?

Using autoscale, the yrange is set to 275:300. Setting explicitly the range to 275:305 would work for one data file but not for others. So I need some generic method to determine the max-data point and set the yrange larger.


回答1:


There are Gnuplot defined values GPVAL_Y_MAX and GPVAL_DATA_Y_MAX (also GPVAL_Y_MIN, GPVAL_DATA_Y_MIN ...). After your plot, the maximum value will be stored in these values. So you can plot your data then set yrange GPVAL_Y_MAX+(GPVAL_Y_MAX-GPVAL_Y_MIN)*0.05. At this time you plot you data for the second time. This time you just get what you want. The following is my code.

    reset
    plot "data.dat" u 1:2 #To get the max and min value
    MAX=GPVAL_Y_MAX
    MIN=GPVAL_Y_MIN
    set yrange [MIN-(MAX-MIN)*0.05:MAX+(MAX-MIN)*0.05]
    #Add a fixed value is not a good idea, so I use a relative one
    set term png
    set output "out.png"
    plot "data.dat" u 1:2 w p notitle #This plot will create a file
    #named out.png which is waht you want.

I learned the method from this article--http://gnuplot-surprising.blogspot.com/2011/09/advanced-background-color-1.html




回答2:


set offsets <left>, <right>, <top>, <bottom>

will do. Note the scale follows the data scale, so it will eventually depend on the data you want to plot. Alternatively, you can use set offsets graph ... to use fraction of the plot size instead.



来源:https://stackoverflow.com/questions/7330161/how-to-access-gnuplots-autorange-values-and-modify-them-to-add-some-margin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!