Get Xrange of current graphics object in IDL - object

How do I get the X-range of the "current" graphics object? For example lets assume I create a single plot window:
p = plot(/test, xrange=[10,35])
Now, without using the reference to p how do I get the X-range ([10,35]) of this plot window?

Related

Using nested for loop in gnuplot

I am trying to plot a set of graphs to compare the simulation results with the experimental data. The simulation files are in ordered arrangement on 7X7X7 for various parameters. I need to plot all of those files using a nested for loop for each iXjXk file. The files are named thus : fibrilAll_i_j_k.dat
I have already tried some alternatives like using multiple for loop in the same line. But it doesn't seem to work.
set terminal eps size 1200,800
set output "all.eps"
set title "{/*2 Alternative rates}"
set ylabel "{/*2 fibril mass fraction}" offset 1.5,0,0
set xlabel "{/*2 Time(h)}"
set key left top
plot 'experiment.txt' using 1:6 ps 2 pt 5 title "EXP",\
for [i=1:7] for [j=1:7] for [k=1:7] 'fibrilAll'._i_j_k.'.dat' using 1:2 with lines title 'i,j,k'
replot
I get the following error message:
internal error : STRING operator applied to undefined or non-STRING variable
I see a few possible problems.
1) I take it you do not want to plot the same file fibrilAll_i_j_k.dat 343 times.
If the data files are named e.g. fibrilAll_1_5_3.dat then you can construct that name by saying plot ... sprintf("fibrilAll_%d_%d_%d.dat",i,j,k)
2) Probably you want something similar for the titles
3) The replot does not accomplish anything. Did you leave out something?

Plotting smooth sphere from discrete data with gnuplot

I have data generated from python code as such:
u, v = np.mgrid[0:2*np.pi:180*1j, 0:np.pi:90*1j]
X = np.cos(u)*np.sin(v)
Y = np.sin(u)*np.sin(v)
Z = np.cos(v)
This is written to a file tmp.dat, and I attempt to plot it in gnuplot with:
set pm3d
set palette
set hidden
splot "tmp.dat" using 1:2:3 with pm3d
However, this gives me:
It's in the general vicinity of what I want, but I'd like a smooth sphere as opposed to this. (My real data is in the same vein; with an enclosed surface I want to have transparency on.) I've tried adding set dgrid3d 50,50 to try and interpolate, however, I don't actually understand what I'm getting from this:
Any help or advice would be enormously appreciated. Changing the data to parametric (with u and v sweep data) is an option, however, I'm not certain how to do that - when I tried, the result was the same.
Not a complete answer, but part of your problem is that "set hidden3d" is not usable here. Gnuplot has two separate subsystems for representing surfaces. One of them, controlled by "set hidden3d", tracks bounding line segments and can remove occluded portions. The other is pm3d, which uses solid-fill quadrangles rather than bounding line segments. pm3d plots do not have the option of removing occluded quadrangles, but you can get a similar effect by depth-sorting them. The relevant command is
set pm3d depthorder
This works reasonably well if the individual quadrangles are approximately square but it gives bad results for long thin quadrangles, since the two ends of the facet can have conflicting depths with regard to neighboring facets.

artifacts in transparent fill when plotting data files with gnuplot [duplicate]

I have noticed that Gnuplot produces ugly artefacts when dealing to filled elements.
One instance is in the palette of the next figure:
Another example is when using filledcurves between two curves defined from points in ASCII files. In this case, you can see that rather than a real solid fill between the lines, the area is filled with number of strips, that only become apparent after zooming quite a bit, but that has very strong impact when rastering the image to png or similar:
This seems to be independent on the terminal. I have tried postscrip, pdfcairo and even tikz. Is there anything that can be done to improve this, or is this a hard limitation of Gnuplot?
Unfortunately, this is an artifact due to antialiasing in the document viewer when you have two filled polygons touching each other. This happens with the filledcurves plotting style, which composes the filled area of many quadrangles, as well as with the pm3d style (as you can see in the colorbox, which shows the same artifacts). See also
problematic Moire pattern in image produced with gnuplot pm3d and pdf output. for a concrete demo case.
There is a workaround, which however is very cumbersome. You must generate a filled polygon object with some script, fill that, use stats to determine the ranges, plot an empty plot (see e.g. Gnuplot - how can I get a figure with no point on it ? (I want to have only the axes, the title and the x- and y- labels)).
I assume, that you have a data file with three columns, and you would plot them with
plot 'test.dat' using 1:2:3 with filledcurves
Using the following very crude python script
from __future__ import print_function
from numpy import loadtxt
import sys
M = loadtxt(sys.argv[1])
print('set object 1 polygon ', end='')
for i in range(0,len(M)):
if (i == 0):
print('from {0},{1} '.format(M[i][0], M[i][1]), end='')
else:
print('to {0},{1} '.format(M[i][0], M[i][1]), end='')
for i in range(len(M)-1,-1,-1):
print('to {0},{1} '.format(M[i][0], M[i][2]), end='')
You can plot the filled curve with
# determine the autoscaling ranges
set terminal push
set terminal unknown
plot 'test.dat' using 1:2, '' using 1:3
set terminal pop
set xrange [GPVAL_X_MIN:GPVAL_X_MAX]
set yrange [GPVAL_Y_MIN:GPVAL_Y_MAX]
eval(system('python script.py test.dat'))
set object 1 polygon fillstyle solid noborder fillcolor rgb 'red'
plot NaN notitle
That, doesn't yet cover the problem with the jagged colorbox :(

Determine min and max in gnuplot

I am new to gnuplot and i am trying to determine the mina nd max from a datafile and afterwards plot the data
So far I have managed to determine the min and max like this:
# Define two helper functions
ismin(x) = (x<min)?min=x:0
ismax(x) = (x>max)?max=x:0
# Initialise the 'global' vars
max=-1e38
min=1e38
plot "Data.txt" u 0:(ismin($3)*ismax($3))
The problem is that I am trying to plot the data using splot, and it's not working.
I am trying this:
splot \
'Data.txt' u 2:1:3 with pm3d t '',\
If I remove the part related to determining the min and max, the splot command works.
Any suggestions?
Look into the stats command:
stats 'datafile' using 3
for example, will get statistics on the 3rd column (z data), and store them in variables (STATS_min and STATS_max may be what you want). To see all the variables created, type
show variables all
after running stats. If you have an older version of gnuplot without stats, you can plot the file without creating an output, and gnuplot automatically defines some DATA_-prefixed variables including a min/max. The stats command saves the trouble of defining a null output to get data before plotting.

gnuplot ignores x and y ranges when using dgrid3d

I have a file with scattered data (points located approximatelly on the vertices of a regular grid): first two columns are the x and y coordinates, then a few more columns with other data that I need to plot. I want to obtain color maps that represent this data, and since points are scattered I'm using dgrid3d to generate a regular grid and have a smoother representation. My problem is that when I set dgrid3d, gnuplot ignores the x and y ranges and plot the grid outside the figure frame. Bellow is a minimal script to reproduce my problem:
set view map
set yrange [0.4:0.8]
set xrange [0.2:0.8]
set pm3d
set style data lines
set dgrid3d 100,100,4
splot "./Terr.dat" using 1:2:(log($6)) pal
The result that I obtain is the following image:
Setting the option clip1in or clip4in of pm3d has no effect. If I unset view so that the result is a 3D surface, it also ignores the x and y ranges. I could easily write an script to pre-process the data and remove the points outside the range I want, but gnuplot should be able to manage this. Any idea?
I'm using gnuplot 4.2 patchlevel 6
Thanks!
I'm not sure that I am able to reproduce your problem, but there are a few funny things with your script. I'm not exactly sure what the line set style data lines is supposed to do in this context as you're plotting with pm3d. I created a simple datafile:
0 1 4
1 0 5
0 0 2
1 1 3
And I plotted it using this script:
set view map
set yrange [0.4:0.8]
set xrange [0.2:0.8]
set dgrid3d 100,100,4
splot 'test.dat' u 1:2:3 w pm3d
And it seemed to "work" (I'm using gnuplot 4.6.0).
There are a few things of note however -- Notice that every point in my original domain was out of the given x and y ranges. Gnuplot still used those points when constructing the surface. This is also demonstrates reasonably nicely what the gnuplot weighting function looks like (although we could do even better by using only 1 point in our data file.)
UPDATE
Between my 2 computers, I have access to gnuplot4.2.6, gnuplot4.3.0, gnuplot4.4.2, gnuplot4.6.0, gnuplot4.6.1 and gnuplot4.7.0. gnuplot4.2.6 is the only version which exhibits the behavior you describe. It looks to me like they changed the behavior of pm3d in the 4.3 CVS branch, but didn't push those changes back into gnuplot4.2. The easy fix is to upgrade to gnuplot4.6 -- I've been using it as my default gnuplot for a few months now and it seems to be pretty stable.

Resources