From: Dima K. <gn...@di...> - 2018-07-21 19:29:55
|
Thanks Karl-Friedrich, Ethan for the suggestions. These both sound like they work, but they also sound like workarounds instead of solutions. I have already found an ugly workaround that works: splot the same data twice: once 'with image' (for the colormap) and again 'with lines nosurface' (for the contours). Comments inline. Ethan A Merritt <sf...@us...> writes: > On Wednesday, July 18, 2018 12:37:17 PM PDT Dima Kogan wrote: >> Hi. I have a matrix data set, and I'd like to plot it using colors (with >> image), AND I'd like to overlay contours on top. This apparently does >> not work. >> >> It looks like 3d 'with image' plots use the data values for colors, but >> NOT for z. I.e. you get a colored image at z=0. Since it looks like >> contours read the z coordinate to do their thing, this doesn't work. > > I will try to explain why "with image" is not a plot style that can be > contoured. > > Consider a typical image file: PNG or GIF or JPEG or whatever. > It contains red/green/blue and maybe alpha values for each pixel. > But no z. Where would you get a z value from? > > <snip> > > Now it is true that gnuplot's "with image" mode can be used for > gridded data where the color information is generated by > index lookup from gnuplot's own continuous color palette. > I guess that's what you are doing, but it is certainly not the general case. In all my experience, I've used 'with rgbimage' for image files (.png, .jpg, ...) and 'with image' for gridded data. And 'help image' describes the gridded data use case first, and at least this suggests that this isn't some sort of side-feature. >> If I plot 'with lines', I get contours. I can also plot 'with pm3d', >> which produces a color AND a z-coordinate, so contours work then. >> >> Questions: >> >> It makes no sense to me that 'with image' 3d plots are stuck at z=0. >> Does ANYBODY want that? > > They are not stuck at z=0. See for example plots 6-8 of the image2 demo: > > http://gnuplot.sourceforge.net/demo_5.2/image2.html All right. If I specify something like "rotate", will I get contours? If not, then I claim that this is surprising to the user, and is thus a bug. My fundamental complaint is this: splot "something" with pm3d gives me contours. 'with lines' and 'with points' give me contours. 'with image' does NOT give me contours. Silently. To a USER who doesn't know or care about the gnuplot internals this is a bug. >> Can we apply the values to color AND z in this >> case? Is this hard, or is there some specific reason we're doing it the >> way we're doing it? >> >> pm3d is intended for irregularly-sampled data (as I understand it) > > Not really. pm3d is a coloring algorithm that can be applied to > anything constructured from quadrangles. Typically this is a regularly > gridded surface. There are also options for interpolating an > irregularly sampled data set to generate a regular grid that can then > be colored (see "help dgrid3d"). But it sounds like your case doesn't > need any extra step to regularize the grid. Without extra options pm3d was re-interpolating my data in some way, so its results weren't the same as 'with image'. And it's doing something different internally, and ends up producing bigger (and presumably less efficient) output. >> is there overhead for using pm3d in this case? Size? Speed? If there's >> no overhead, can 'splot with image' simply map to 'splot with pm3d'? > > In gnuplot version 5 you can tell pm3d to use a pre-calculated > RGB color for each grid point. This RGB value must be in the form of > a 24-bit packed RGB integer. I don't know exactly what the nature of > the values in your matrix so I cannot provide exact instructions, > but in essence the command sequence would be > > set pm3d border lc rgb variable > set style fill solid 1.0 > splot $DATA using 1:2:3:(rgbfunc($3)) with pm3d > > It is up to you to define rgbfunc() appropriately. > Here is an example using a regularly sampled grid and a constant > color value: > > set xrange [-2:2] > set yrange [-2:2] > set sample 20 > set isosample 20 > > splot '++' using 1:2:(cos(y)*sin(x)):(int(0xdd77aa)) with pm3d > > But your special case may not require any of that. > If the "z" values on a regular grid are to be used also as a palette > index then indeed the default pm3d settings may be sufficient. Thanks for the example. I'll keep this usage in mind for the future, but it's not applicable to my immediate use case: I have 1-dimensional values, so the default gnuplot colormapping is what I want. >> If nothing else, can we barf instead of silently not rendering the >> contours in the 'with image' case? > > The more common complaint is that too many error messages > are printed for things that are not fatal errors. > Consider a hypothetical plot that includes some contours, some image data, > and some other stuff: > > set contour > splot A with lines, B with image, C with vectors > > The result is a plot with contours for A and no contours for B or C. > What would be the benefit of spewing errors or failing just because > B and C are plotted using styles that cannot be contoured? Yeah, this is an unfortunate consequence of the way we set up our interface. Ideally, you'd specify the contour options per plot: splot A with lines contours, B with image contours, C with vectors Changing this retroactively is probably more trouble than it's worth. OK. Let me look at the code and see if I can make 'with image' do what I think it should do. Don't know when I'll get to it, but that will make this into a more concrete discussion. dima |