简体   繁体   English

在R或gnuplot中以相似的比例绘制不同的等高线图

[英]Plotting different contour plots with similar scales in R or gnuplot

I am new to R for plotting, and I wish to do contour plots for several files. 我是R绘图的新手,我希望为几个文件做轮廓图。 and here is what I have got so far. 这是到目前为止我得到的。 My file has 3 columns, X,Y,Z, and with some nan values. 我的文件有3列X,Y,Z和一些nan值。 Since lattice does not allow Inf/NaN values, I had to remove them prior, and do some interpolation. 由于点阵不允许使用Inf / NaN值,因此我必须先删除它们,然后进行一些插值。

data <- read.table("file", sep=",", header=T)
mydata <- na.omit(data)
library(akima)
library(lattice)
s = interp(mydata$X, mydata$Y, mydata$Z)
filled.contour(s, xlim= c(5,25), ylim=c(40,180))

This does gives some results, but there are things I am not able to do: 这确实给出了一些结果,但是有些事情我做不到:

  1. To get contour lines on the graph. 在图形上获取轮廓线。
  2. Also there are like 3 files with different z ranges, say one from (0-18), (0-20), (0-25). 另外,还有3个文件的z范围不同,例如(0-18),(0-20),(0-25)中的一个。 I wish to adjust and rescale them to provide similar color scale on graph, for instance, the '15' value should be similar color on all three. 我希望对其进行调整和重新缩放以在图形上提供相似的颜色比例,例如,“ 15”值在所有三个颜色上都应相似。

I am more familiar with gnuplot, but there also the problem is with the ranges, as the range always autoscale to color, and it seems difficult to control the range. 我对gnuplot较为熟悉,但问题还在于范围,因为范围总是自动缩放为彩色,并且似乎很难控制范围。 Any help with that is also deeply appreciated. 对此的任何帮助也深表感谢。
I may be doing something wrong, so in case anybody could help me out, and provide to right direction, or right software, I will be grateful. 我可能做错了,所以如果有人可以帮助我,并提供正确的指导或正确的软件,我将不胜感激。

There are demos here for how to make contours in gnuplot. 有演示这里如何使轮廓在gnuplot的。 Are you having trouble in the sense that you have code to make a contour plot but it does not work? 您是否有编写轮廓图的代码的麻烦,但是它不起作用?

To answer your second question, in gnuplot the command you probably want is 要回答第二个问题,在gnuplot中,您可能想要的命令是

set cbrange [CB_MIN:CB_MAX]

This sets the range of values which will be colored according to the current palette. 这将设置将根据当前调色板上色的值的范围。 You would just have to issue the same set cbrange command for all three plots you are making. 您只需要对要制作的所有三个图发出相同的set cbrange命令。 If you want to automatically set the cbrange to the min/max on all files, you can use the stats command (in version 4.6 or newer, otherwise it is more tricky): 如果要在所有文件上自动将cbrange设置为min / max,则可以使用stats命令(在4.6版或更高版本中,否则比较棘手):

stats 'datafile1' using 3 name 'd1'
stats 'datafile2' using 3 name 'd2'
stats 'datafile3' using 3 name 'd3'
datamin_z = (d1_min<d2_min&&d1_min<d3_min?d1_min:d2_min<d3_min?d2_min:d3_min)
datamax_z = (d1_max>d2_max&&d1_max>d3_max?d1_max:d2_max>d3_max?d2_max:d3_max)
set cbrange [datamin_z:datamax_z]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM