Well, I am trying to plot a matrix-like data file using pm3d option as follows
set pm3d map
set pm3d interpolate 0,0
splot namefile matrix
I have tried to upload an image but it seems I don't have enough reputation. Ok, so the problem is that the data come from logarithmic binned x and y axes, but the default option for the tics separation is the lineal one (1, 2, 3, ... ). If I want to rescale the tics to another interval, it is easy as long as I keep this linearity ( e.g: 0, 10, 20,... ). However I would like to rescale them to my data interval but logarithmically separated (1, 10, 100,... ). Of course, what I only want to change are the tics, whereas the proportion within the plot is kept the same.
After thinking and looking around I could not find a satisfactory answer. Any hint on how to solve it ?
Thank you !
If you only want to change the tics, but not the scaling of the data you must manually set the tics like
set for [i=1:5] xtics add (sprintf('%.0f', 10**(i-1)) i)
set for [i=1:5] ytics add (sprintf('%.0f', 10**(i-1)) i)
Related
Contour lines generated by gnuplot can look pretty strange (unexpected) if you do not set both samples and isosamples to appropriate values. I struggled for hours to find out how exactly set samples and set isosamples affect the appearance of contour lines, however, all I observed is that setting both to sufficiently large values will generate good-looking contours. Still, I want to understand how exactly this works.
What is the difference between set samples and set isosamples in the context of contour lines?
How does set samples affect the generation of contour lines?
How does set isosamples affect the generation of contour lines?
For example, consider the following simple case:
unset surface
set contour
set cntrparam levels discrete 10, 20
set samples 250, 2
set isosamples 2, 250
set view map
splot x**2 + y**2
To generate correct contour lines, it appears you need to set the first parameter of samples and the second parameter of isosamples to sufficiently large values. However, setting the second parameter of samples and the first parameter of isosamples to the smallest possible value does no harm. This is not exactly intuitive. So how does this work?
First, a discussion on what samples and isosamples where designed to do. This is best when viewing the actual plot and not the contour map.
samples is used to set the number of function evaluations along an axis in the range being plotted. For splot (3-D images), you can control samples in both independent directions x and y. Here is a sample where the x-direction only has 4 evaluations and the y-direction has 200:
reset
set xrange [-10:10]
set yrange [-10:10]
set xlabel 'X'
set ylabel 'Y'
set samples 4,200
splot x**2+y**2
In the following 2 images note that along the x-direction, the function is only evaluated 4 times and straight lines are drawn between them. Along the y-direction, it is evaluated 200 times and it looks like 'smooth' curves. Note that in both directions, exactly 10 lines are drawn. I will get to that below while discussing isolines.
Looking toward x-axis:
Looking toward y-axis:
So, 10 lines in each axis direction are drawn because the default value for isolines in both x and y directions is 10. We can change this at will. Lets increase samples in both directions for a nice smooth curves but demonstrate isosamples.
reset
set xrange [-10:10]
set yrange [-10:10]
set xlabel 'X'
set ylabel 'Y'
set samples 200,200
set isosamples 4,12
splot x**2+y**2
Note the nice smooth curves in both directions. Along the x-axis, there are only 4 points where, along the y-axis, the surface curves are drawn and along the y-axis, there are 12 points where surface curves are drawn parallel to the x-axis.
The above examples demonstrate the primary purpose of set samples and set isosamples. They only indirectly affect contours. In your case, you are only interested in the contour map without even displaying the surface plot. A clue as to how gnuplot plots contours is in its explanation of how contours can be drawn with discreet data.
Gromacs:
In order to draw contours, the data should be organized as "grid data". In
such a file all the points for a single y-isoline are listed, then all the
points for the next y-isoline, and so on. A single blank line (a line
containing no characters other than blank spaces and a carriage return and/or
a line feed) separates one y-isoline from the next.
From this explanation, gnuplot seems to prefer to pick an x value and draw a y-isoline. We can deduce then that when gnuplot draws contours from functions, that it picks x values and draws y-isolines. Therefore having many x samples and many y isolines draws hi resolution contours while the y samples and the x isolines are irrelevant (if you are not drawing the surface).
I'm currently plotting a several plot one side to side. Since there are lots of graphs, I need to waste as little space as possible. At the moment I have this situation:
I want to "right align" the number associated to the first tic in the X axis and "left align" the number associated to the last tic in the X axis. In this way I can achieve the following (saving some pixels):
At the moment both tics and number are set automatically. Is there a way to achieve this in gnuplot? I know you can set via xtics left|center|right the alignment of all the values in the axis.
Regardless of my objective to achieve plot compactness (this may be a XY problem), the question still remains: but does exist a method to manually set the alignment of a particular tic?
Thanks for any kind reply
NOTE: I didn't wrie the version of gnuplot since using a particular version is not a requirement to solve the question.
not very clean solution, but you could for example first define the tics globally and then manually "override" the particular ticks "of interest":
set xr [0:100]
set yr [0:100]
unset key
set xtics 0,20,100
set xtics add (" 0" 0 0)
set xtics add ("100 " 100 0)
plot x w l lc rgb 'dark-red' lw 2
unfortunately, it seems that doing something like this:
set xtics 0,20,100
set xtics add right ("100" 100 0)
affects the alignment of all ticks and not just the added one...
What bugs me in changing the position of only the first and last tic marks is that the space between the labels 20 to 30 won't be the same as 30 to 40 and so on. I've had this problem in the past, and you can play with the number of tics and the range. For example:
set xtics 10
set xrange[15:105]
or if you really want to stick to the 20:100 range:
set xtics 15
set xrange[20:100]
You can also add mxtics to make it look even prettier. This is not a formal solution by any means, just a nice workaround. Hope it helps.
I have an ASCII data file (density.dat) in the format (x y D), where D represents a density-value at the point (x,y), from which I create a colormap:
set pm3d interpolate 2,2 corners2color mean
set view map
splot data_file u (1e9*$1):(1e9*$2):3 with pm3d
I have a second data file (potential.dat) with the same format (x y P), where P represents a potential value which can only have one of two values zero or 1.0 (say). I would like to indicate the boundary between the (three) regions (a straight line with slight perturbations) where the potential is zero and the regions where it is non-zero and overlay it on the first colormap of the density.
I though the approach where I plot the contours from one file on the plot of another file (similar to here), could work but the exported data using the 'set table filename' cannot be used for 'plot filename with image' it seems.
I would greatly appreciate ideas (or solutions..) to tackle this problem.
======== EDIT ==========
Working solution for me:
set contour base
set cntrparam level discrete 1.0
splot density_file u 1:2:3 with pm3d nocontour,\
potential_file u 1:2:3 w l nosurface
In the link you give, with image is used to plot the colour map, not the isolines, these are plotted with lines. I am not sure why you need to go through a table at all, it seems that you can handle everything with splot commands, unless you want to make fancy customisations or have strong constraints with margin control. See the discussion at the top of the post
http://gnuplot-tricks.blogspot.co.uk/2009/07/maps-contour-plots-with-labels.html
You will need to give more details in your post if you want a more precise answer.
I have temperature data from eight different nonequidistant depths over several days and I would like to plot it as heatmap. As far as I know I have two options. I can use "with image" but that assumes equidistant points so that makes just 8 pixel thin strip or I can use pm3d which need proper grid(I am not sure what proper grid is). I found that dgrid3d can make the grid for me but that erases any dependency on depth for some reason. Can someone please explain this behavior to me?
Here is the code and the data I use.
https://docs.google.com/file/d/0B2TfUgjtGRVReV9ocFVvM1BKd2M
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
set view map
set dgrid3d
splot './Data/MO-03t_.txt' every ::2 u 1:3:4 with pm3d
the dgrid3d does not plot your data. Instead, something like two-dimensional splines are calculated from your data. Then, gnuplot creates a (by default) 10x10 matrix, and fills it with values interpolated from the splines. This matrix is then plotted.
But I have an other solution for you:
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
# for the nice colors
set pm3d
# For debugging: place ticmarks only vor values with data
set ytics (0.02, 0.04, 0.06, 0.11, 0.31, 0.41, 0.61, 0.91)
plot './Data/MO-03t_.txt' every ::2 u 1:3:(1800):($3<0.2?.005:0.05):4 w boxxyerrorbars fs solid lc palette
The boxxerrorbars ... lc palette takes using <x>:<y>:<deltaX><deltaX>:<z>
The delta values are half the width of the boxes, i.e. it means plot a box from x-deltaX;y-deltaY to x+deltaX;y+deltaY for each datapoint.
Here, the width of the boxes is 3600 seconds, the height is either 0.1 or 0.01, depending on the y-value.
Here is the result:
However, you can still improve the height of the boxes.
And instead of 4+1 columns, you can also pass 6+1 columns with
using <x>:<y>:<xlow>:<ylow>:<xhigh>:<yhigh>:<z>
Here, the borders of the boxes are given as absolute values, not as distance from the x-y-value.
Currently I created graphs with small size. The spacing really important at this case. I want to add more vertical space between my xticlabels and x axis.
I have tried to set the x bar with
set xtics offset 0,graph 0.05
my gnuplot output:
The data and gnuplot script still same with my previous question here.
You can do the following:
First add a little bit of bmargin by
set bmargin 3
Since you need to add vertical space between your xticlabels and x-axis, you need to adjust the Y-offset, which can be done by the following
set xtics offset 0,-1,0
You can play around with the values to suite your need.