I wrote code to make a 3d plot from an xyz datafile (see "3d-2d projection 1.png"), followed by a 2d plot of the same data (see "3d-2d projection 2.png") in a separate window. I would like to combine these two plots by adding the 2d plot to the xyplane of the 3d plot which I offset negative so they won't overlap. I can't figure out how to do this. Can someone help? I find plenty of examples for plotting 3d equations with a surface projection but I am using dots to plot discrete data values in this case.
Here is the 3d part of my plot code which I want to modify to add 2d projection onto xyplane:
set terminal qt 0 size 1280, 768 position 0, 0
set key off
set pm3d
set grid back
set border 4095
set view 60, 60, 1, 1.25
set xyplane at -1.15
set palette color
set colorbox user origin .9, .23, 0 size 0.03, 0.45, 0
set tics out
set datafile separator comma
splot [0:1155] [0:2039] [0<:<1] 'datafile.csv' with dots palette
I may not understand what you want, but if your 3D plot is
the projection onto the xy plane just
Hi Ethan, thanks for the quick reply. If I take your suggestion literally and replace my splot line with yours I get the attached plot (see "trial1.png").
I also get these warnings:
gnuplot> Warning: empty z range [0:0], adjusting to [-1:1]
Warning: empty cb range [0:0], adjusting to [-1:1]
If I merge your suggestion with my existing splot line, i.e.,
splot [0:1155] [0:2039] [0<:<1] 'datafile.csv' using 1:2:(0) with dots palette
I get similar (see "trial2.png") with same warnings.
This is clearly not the result I need.
Ah, OK. Sorry. I was just thinking of the location of the points, not the color. To preserve the color you want
We're one step closer, in a sense. Trial3.png shows that now I'm getting a 2d plot, see attached "trial3.png."
But several steps back:
I need to retain the 3d plot, not replace it.
I need the 2d plot to be at the bottom.
I need the colorbox to have same scale 0 to 1 (went 0 to 2.5)
The pm3d demo gives a good example of what I'm shooting for. See "pm3d at b.png", in which I added this line to demo:
set xyplane at -2
Just imagine the mesh plot is my 3d points plot. I want the 2d plot added like in this demo.
Of course you need to add this to your previous command, not replace it.
It will go at whatever coordinate you give it.
You asked for a plot "to the xy plane" so I showed a command with z=0.
You can give z = -10 or whatever.
Not sure what you mean here. All of the plots discussed so
far use the same cbrange, autoscaled from the contents of
column 3 in your input data. You can provide an explicit range if you like:
set cbrange [0:1]
But then any of your data points with z value outside that range will
have their color pinned to one of the range endpoints.
You may be confused by observing that the projected plot looks
very purple. That is because in projecting the full set of points
you haven't changed their ordering. If a purple dot is placed on top
of a yellow dot, all you see is the purple. To avoid this you'd
have to sort the points on z.
Going back to my original code, you can see I define a z_range of [0<:<1] which limits low/high to 0/1 but otherwise autoscales within this. All of my z data is between 0 and 1, and there is exactly one z data value for every pixel coordinate x, y so there are no dots being placed on top of other dots. The last trial gave me scattered dark pixel colors near the edges as expected but the rest was blue because the scale had changed to 0-2.5 from 0-1. Most of my data is near 0.5. But I think I understand that it was autoscaling because my trial3 splot command didn't have the ranges included.
So how do I add a 2d plot to the 3d plot command? I tried this:
splot [0:1155] [0:2039] [0<:<1] 'datafile.csv' with dots palette, '' using 1:2:(-1.15):3 with dots lc palette
and got no errors but also got no 2d plot, just the 3d. Note that I used (-1.15) to match my xyplane offset as you suggested. At least my colorbox is staying in range 0-1 now.
By the way, what is linecolor (lc) parameter doing for me?
I feel like I'm close, just missing that last detail to make it work.
Opinions differ, but mine is that if you have to put range limits at the start of the plot command then you're doing something the wrong way. In general they don't act as you might expect.
In this case you've told it not to plot anything outside the z range [0:1] so of course your entire surface at z=-1.15 is out of range and therefore not plotted.
I take it that's not what you want, but I'm not clear what you do want since you say that all your data is between 0 and 1 anyhow so why are you imposing range limits?
Try
set xrange [0:1155]
set yrange [0:2039]
set style data dots
splot 'datafile.csv' lc palette, '' using 1:2:(-1.15):3 lc palette
The "lc palette" is telling it how to interpret the final (3rd or 4th) column of input data. Probably it will accept just "palette". You could, for instance, have provided an extra column of input that contained a color rather than a z value.
Didn't want to confuse you, Ethan--all of the data points I CARE about are between 0 and 1, there are some outliers above 1.0 which I choose to scale out, but autoscale was acting on those too of course.
I thought the whole idea of z_range was so that points outside it don't get plotted (or they get clipped, I don't care). And that a 2d plot would always put points down on the xy plane no matter where it is offset to. Apparently that's not so I guess. But since the offset of the xyplane is causing none of the points to get plotted, then would my solution simply be to offset every data point by -1.15? How would I do that? Does this also mean my colorbox range of 0-1 would make every dot show up as black?
Somehow the pm3d demo is getting colors at my negative xyplane value of -2 which is outside the colorbox min of -0.4. I looked at the demo code and there are almost no commands creating those plots so I don't understand how it's getting done.
Sort of. The zrange sets the limits of the plot itself, and points outside the plot don't get plotted. But it's not a direct filter on the z coordinates of the input data. For that we usually recommend
splot FOO using 1:2:($3 < limit ? $3 : NaN)
or something of that sort. That makes it independent of what the limits of the full plot might be. As in the current case, you might have multiple components with differing z range.
No. Just forget that idea.
This gets a bit more complicated. By default both the z range and the colorbar range autoscale to the same component of the data - column 3.
But that is only a default. They can become decoupled.
In the 3D component of your plot both the z range and the colorbar range are
extended to span the range of your data z coordinates.
In the "2D" component of your plot the z range will autoscale to the
third component of the "using" specifier, which happens to be -1.15 or whatever, and the colorbar range will autoscale to the 4th component of
"using", which happens to be column 3 of your input.
So far this comes out the same. But if you now start filtering the Z range of the first plot without equivalently filtering the colorbar range of the second plot, then the 3rd input data column will contribute differently to the autoscaling of z and cb. For this reason you may wish to set the cbrange explicitly to match the post-filtering range of z coordinates in your first plot.
The pm3d plot style is a different plotting mode altogether. None of your trials so far have used pm3d mode. It requires a continuous surface rather than a random collection of points. Your data might satisfy that since it lies on a grid rather than randomly, but you need to present it correctly to the program. That's a whole 'nother discussion and I'm not the best one to advise you on how to set that up.
One final thing you could try:
set hidden3d
This will draw the points in order from back to front, which might look better. But it wasn't designed to work with "dots" so I don't guarantee the
result.
I really appreciate the extra explanations, clearly I'm a novice and these cryptic plot parameters are tricks I need to learn about. Something can be said for the old days when user manuals were on real paper, all info was within a chapter, and you didn't have to hunt for answers with hyperlinks...
But wow what a powerful graphing tool! (my boss says my gnuplots are better than his matlab!)
Well, I took your latest suggestion and got it working!
set xrange [0:1155]
set yrange [0:2039]
set zrange [-1.15:1]
set cbrange [0:1]
set style data dots
splot 'datafile.csv' lc palette, '' using 1:2:(-1.15):3 lc palette
Now I need to understand exactly why it works...
But thanks for sticking with me. You saved me lots of headache.
JP