From: Ethan A M. <sf...@us...> - 2018-07-18 22:32:01
|
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? It is true that PNG or GIF can also encode indexed color. But the sequentially indexed color values do not necessarily correspond to a continuous palette like the ones that gnuplot can generate. So the matrix of index values is not generally something that can be meaningfully contoured. 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. > 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 > 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. > 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. > 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? Ethan > Thanks! > > |