tag:blogger.com,1999:blog-4020452510052679998.post2760430523209323381..comments2020-06-23T10:20:31.923-07:00Comments on Gnuplot tricks: The map, the inline function, and the macroGnuplotterhttp://www.blogger.com/profile/10560778800525149384noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-4020452510052679998.post-35368113354394959602013-12-02T12:22:27.818-08:002013-12-02T12:22:27.818-08:00Hi Gnuplotter,
Thank you for your generous and tho...Hi Gnuplotter,<br />Thank you for your generous and thoughtful posts. They are truly helpful.<br />I am trying to implement the above gnuplot command sequence but have<br />not yet succeeded. When I press enter after the last line I get an warning<br />message that says: Skipping data file with no valid points. I have typed<br />your code verbatim. The image that is generated in the end is the contour <br />map without the level curves. Do you have any idea what might be causing <br />this error? Thank you very much for your blog postings, and any help you <br />might be ableto offer would be greatly appreciatedL={}BoTT=https://www.blogger.com/profile/04132191516002562601noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-59062583162566157662013-06-28T09:59:01.899-07:002013-06-28T09:59:01.899-07:00Genius!
wow, gnuplot is really mind-bending...Genius!<br />wow, gnuplot is really mind-bending...powerkovhttps://www.blogger.com/profile/05436758292285579579noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-29492914784059406042011-05-25T13:31:48.434-07:002011-05-25T13:31:48.434-07:00In the older post the gawk script was modified suc...In the older post the gawk script was modified such that the labels were rotated parallel to the contour lines. Has anyone come up with a way to do this within gnuplot?<br /><br />The ideas presented here are incredibly helpful. Thank you to everyone who has chipped in.Dannyhttps://www.blogger.com/profile/09849912645512548475noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-50542045682352318022011-05-24T11:15:40.997-07:002011-05-24T11:15:40.997-07:00Hi Ricardo,
Do you run gnuplot 4.4?
Cheers,
Zolt...Hi Ricardo,<br /><br />Do you run gnuplot 4.4? <br />Cheers,<br />ZoltánGnuplotterhttps://www.blogger.com/profile/10560778800525149384noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-70427613579388219932011-05-12T01:24:00.478-07:002011-05-12T01:24:00.478-07:00Hi...
I'm using this script as a cooking recip...Hi...<br />I'm using this script as a cooking recipe.. :) sorry for this... <br />I would create a graph of a energy landscape.<br />My only problem (maybe) is that when I give the "g(x,y)=(((x > xl && x < xh && y > yl && y < yh) ? (x0 = x, y0 = y) : 1), 1/0)" instruction, gnuplot reply me with this: " ^<br /> ')' expected<br />"<br /><br />I don't know why... but if you can help me... Thank you!!!Riccardohttps://www.blogger.com/profile/12652045813546636330noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-82266136585033447922010-09-03T00:43:50.686-07:002010-09-03T00:43:50.686-07:00> I found a bug in the code. Namely, you ought ...> I found a bug in the code. Namely, you ought to multiply, not divide, by xtoy^2 in order to achieve the correct result. The code should therefore be<br /><br />> f(x,y) = ((x-x0)*(x-x0)+(y-y0)*(y-y0)*xtoy*xtoy > eps ? y : 1/0)<br /><br />Yes, you are absolutely right. Thanks for posting it! I will just update the post.<br />Cheers,<br />ZoltánGnuplotterhttps://www.blogger.com/profile/10560778800525149384noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-6716883021130505182010-09-01T12:28:34.062-07:002010-09-01T12:28:34.062-07:00Hi Gnuplotter! First of all, thank you for this po...Hi Gnuplotter! First of all, thank you for this post, which was really useful.<br /><br />I found a bug in the code. Namely, you ought to multiply, not divide, by xtoy^2 in order to achieve the correct result. The code should therefore be<br /><br />f(x,y) = ((x-x0)*(x-x0)+(y-y0)*(y-y0)*xtoy*xtoy > eps ? y : 1/0)<br /><br />Again, thanks a lot.Ruggerohttps://www.blogger.com/profile/13221489450874500478noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-47457252135544049562010-06-30T14:38:21.634-07:002010-06-30T14:38:21.634-07:00Greetings penguinny,
Thanks for visiting, and for...Greetings penguinny,<br /><br />Thanks for visiting, and for your comments! I am glad that you came across some useful tricks here. I found your solution to the problem you mentioned especially brilliant. I have to admit that, while I was aware of the difficulty with the positioning of the labels, I was just too lazy to think about the actual solution. Many thanks for sharing!<br />Cheers,<br />ZoltánGnuplotterhttps://www.blogger.com/profile/10560778800525149384noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-30326029060052002082010-06-30T12:14:29.100-07:002010-06-30T12:14:29.100-07:00I am sorry, it seems that HTML processing just mes...I am sorry, it seems that HTML processing just messed up the code. Let me try again:<br /><br />reset<br />unset key<br />set macro<br />set xrange [xi:xa]<br />set yrange [yi:ya]<br /><br />set tics out nomirror<br />set palette rgbformulae 33,13,10<br />eps = 0.001<br /><br />min(a,b) = ((a<b)?a:b)<br />xd = xa - xi<br />yd = ya - yi<br />g(x,y) = ((( min(min(x-xi,xa-x)/xd,min(y-yi,ya-y)/yd)>=dist )?( x0=x,y0=y,dist=min(min(x-xi,xa-x)/xd,min(y-yi,ya-y)/yd) ):1),1/0);<br />f(x,y) = ((x-x0)*(x-x0)+(y-y0)*(y-y0)/xtoy/xtoy > eps ? y : 1/0)<br />lab(x,y) = ( (x == x0 && y == y0) ? stringcolumn(3) : "")<br /><br />ZERO = "x0 = xi - (xa-xi), y0 = yi - (ya-yi), b = b+1, dist = 0"<br />SEARCH = "filename index b using 1:(g($1,$2))"<br />PLOT = "filename index b using 1:(f($1,$2)) with lines lt -1 lw 1"<br />LABEL = "filename index b using 1:2:(lab($1,$2)) with labels"<br /><br />b = 0<br />dist = 0<br />plot 'test.dat' with image, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABELAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-57181124907799760902010-06-30T12:08:00.223-07:002010-06-30T12:08:00.223-07:00Dear gnuplotter,
Many thanks for this truly inspi...Dear gnuplotter,<br /><br />Many thanks for this truly inspirational post! I just finished a contour plot for my paper using a variation of your method. The only snag in my case was with the positioning of labels, which were not nicely scattered around as in your example, but piled along one of the edges (this seems to be related to the order of points in the data file, which is outside of my control). Positioning tends to work ok for gnuplot-generated meshes, but even then it becomes a bit suspect for smooth functions: try using "xi = -5; xa = -4; yi = 4; ya = 5;" in your script above.<br /><br />One solution to this problem is to use some measure of the distance from label to the border as the positioning criterion. This is what I came up with after few experiments:<br /><br />reset<br />unset key<br />set macro<br />set xrange [xi:xa]<br />set yrange [yi:ya]<br /><br />set tics out nomirror<br />set palette rgbformulae 33,13,10<br />eps = 0.001<br /><br />min(a,b) = ((a=dist )?( x0=x,y0=y,dist=min(min(x-xi,xa-x)/xd,min(y-yi,ya-y)/yd) ):1),1/0);<br />f(x,y) = ((x-x0)*(x-x0)+(y-y0)*(y-y0)/xtoy/xtoy > eps ? y : 1/0)<br />lab(x,y) = ( (x == x0 && y == y0) ? stringcolumn(3) : "")<br /><br />ZERO = "x0 = xi - (xa-xi), y0 = yi - (ya-yi), b = b+1, dist = 0"<br />SEARCH = "filename index b using 1:(g($1,$2))"<br />PLOT = "filename index b using 1:(f($1,$2)) with lines lt -1 lw 1"<br />LABEL = "filename index b using 1:2:(lab($1,$2)) with labels"<br /><br />b = 0<br />dist = 0<br />plot 'test.dat' with image, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL, @ZERO, \<br />@SEARCH, @PLOT, @LABEL<br /><br />Who knows, maybe, after few more iterations this will help someone to produce that perfect map!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-89903870683247557582010-05-21T08:36:58.303-07:002010-05-21T08:36:58.303-07:00Dear Gnuplotter,
I agree with Thoro, this is just...Dear Gnuplotter,<br /><br />I agree with Thoro, this is just awesome!<br /><br />Like Joce, tried to adapt your method to a slightly different scenario, in my case : squattered data points...<br /><br />Basically I have a number of squattered data points (x,y,z), x and y being the "coordinates" and z the value. <br />Adding the contour as you did it in your example would be great as this would make the plot easier to read and make it easy to identify the extrema area. But unfortunately a parametric approach is not possible there.<br />(Will stick with the traditional -not so nice- contour line then!..)<br /><br />For record I can show you what I tried to do with awk (which did not work very well...probably because I tried to add it as part of a multiplot that I started with splot's )(yeah...life is complicated! ;-) ) :<br /><br />reset<br />set xrange [*:*]<br />set yrange [*:*]<br />set isosample 20, 20<br />set table 'test.dat'<br />splot 'acidYplus0.1.txt' using 2:3:(sqrt(($4-21.263)**2)/21.263*100):(sqrt(($4-21.263)**2)/21.263*100) w pm3d<br />unset table<br />set cont base<br />set cntrparam level incremental -3, 0.5, 3<br />unset surf<br />set table 'cont.dat'<br />splot 'acidYplus0.1.txt' using 2:3:(sqrt(($4-21.263)**2)/21.263*100):(sqrt(($4-21.263)**2)/21.263*100) w pm3d<br />unset table<br />reset<br />set xrange [*:*]<br />set yrange [*:*]<br />unset key<br />set palette rgbformulae 33,13,10<br />l '<./awk.sh cont.dat 0 15 0'<br />p 'test.dat' w ima, '<./awk.sh cont.dat 1 15 0' w l lt -1 lw 1.5Unknownhttps://www.blogger.com/profile/16043106992751721417noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-50510356388274722302010-04-05T02:31:31.723-07:002010-04-05T02:31:31.723-07:00> Yes, a colour gradient in (each of) the trian...> Yes, a colour gradient in (each of) the triangle(s) is what I'm looking for. It's actually the colour-map plot of a piecewise linear function f(x,y). This corresponds to what you get from a finite elements PDE resolution.<br /><br />I haven't yet worked out the details, but here is how you could start: given the triplet (x1,y1,z1)-(x2,y2,z2)-(x3,y3,z3), take an arbitrary parametrisation of the triangle. Then, read out the numbers in the file, and add parametric plots based on your parametrisation to a string. Once you are done with it, evaluate the string. I believe that all you have to do is to find the parametrisation, and then use what I discussed in my post "Parametric plot from a file". Let me know, if this works! If you still have problems, I will just write it up in a post.<br /><br />> The software plotmtv (in all good linux repos) for instance will produce the colour map, if you add the commands<br /><br />I hadn't known this software, but after you mentioned it, I checked it out. However, it seems that it is no longer maintained. <br />Cheers,<br />ZoltánGnuplotterhttps://www.blogger.com/profile/10560778800525149384noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-49717460299121158502010-04-04T13:59:59.511-07:002010-04-04T13:59:59.511-07:00Dear Gnuplotter,
I want to plot a potential energ...Dear Gnuplotter,<br /><br />I want to plot a potential energy map which has several peaks. The script presented here works well for a smooth gradient of values, but doesn't really for more complicated shapes. In particular, I found difficult to control which iso surface has to be labelled.<br />Furthermore, the file containing the isosurfaces also includes some isocurves that appear on the plot as straight lines. To fix it, I have to manually edit such file and then run again the script.<br /><br />Could you have a look at my files? They are <a href="http://rapidshare.com/files/369855895/test_clabels.tgz.html" rel="nofollow">here</a>.<br /><br />Thank you very much for this useful blog :)HotHellohttps://www.blogger.com/profile/05778316944673315877noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-68598777696211554142010-04-03T06:41:04.674-07:002010-04-03T06:41:04.674-07:00Yes, a colour gradient in (each of) the triangle(s...Yes, a colour gradient in (each of) the triangle(s) is what I'm looking for. It's actually the colour-map plot of a piecewise linear function f(x,y). This corresponds to what you get from a finite elements PDE resolution.<br /><br />Alternatively, an elevation plot of f(x,y) would also be interesting.<br /><br />I'm unfortunately quite unable to produce such a colour-map plot with gnuplot from data of the type I've given. Gnuplot handles this type of data as a 1D curve (x,y,z=f(x,y)).<br /><br />In the case of elevation it is doable, as splot readily gives (nearly) what I want from the data file above, except that the last edge of the triangle is missing. One could add it either by repeating the first line of each block at the end of the block, or possibly using the new `for' command.<br /><br />Oh, and one thing of importance, the triangle summits are generally not aligned on any grid, the only property of these triangles is that they don't overlap (and that across a given edge, if they have a neighbour then this neighbour shares the full length of the edge, but that's not important for plotting)<br /><br />The software plotmtv (in all good linux repos) for instance will produce the colour map, if you add the commands<br />$ DATA = CONTCURVE<br />%contstyle=2<br />%nsteps=50<br />to the head of the data filejocehttps://www.blogger.com/profile/08294153311519669538noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-59887416791556174982010-04-02T13:12:11.625-07:002010-04-02T13:12:11.625-07:00Hello Joce,
I am not sure I understand the proble...Hello Joce,<br /><br />I am not sure I understand the problem, so perhaps, we should further discuss it. Let us take one element for a start! So, in your example, you have the triangle given by the following triplet<br /><br />(0,0)-(1,0)-(0,1)<br /><br />First I thought that the idea was to colour this triangle as red, say, but your points have different numbers assigned to them. Do you, perhaps want to have a colour gradient on this triangle, in such a way that the (0,0) point is read, the (1,0) and (0,1) points are blue, say? Could you, perhaps, post an example of such a plot?<br />Cheers,<br />ZoltánGnuplotterhttps://www.blogger.com/profile/10560778800525149384noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-59265068036534108192010-04-01T23:58:30.300-07:002010-04-01T23:58:30.300-07:00Hello Zoltán,
Time for a challenge ... ;-)
One t...Hello Zoltán,<br /><br />Time for a challenge ... ;-)<br /><br />One thing I miss with gnuplot is being able to plot colour maps from finite element type data, eg :<br /><br />#Element 1<br /># x y val<br />0 0 1<br />1 0 2<br />0 1 2<br /><br />#Element 2<br /># x y val<br />1 0 2<br />1 1 3<br />0 1 2<br /><br />This data corresponds to the function f(x,y)=x+y+1 on a mesh composed of 2 triangles.<br /><br />Do you think one could plot this sort of data ? And would it be manageable with 1000s of triangles ?<br /><br />Gnuplot is such a great tool, because once you can plot then any analytic transformation/comparison is possible...<br /><br />jocejocehttps://www.blogger.com/profile/08294153311519669538noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-83716246272929620462010-02-24T12:43:29.661-08:002010-02-24T12:43:29.661-08:00Hello Thoro,
First, thanks for the kind words! As...Hello Thoro,<br /><br />First, thanks for the kind words! As to your questions, could you please, post the script that you want to use? Perhaps, the data file too, or if it is too big, a function that would generate similar data? It might not be important what exactly it is, for it seems that you have problems with the log scale, so I would just like to see the range settings, and so on. The script should probably be enough. <br />As for the second of your questions, you can produce "portrait" figures, if you set the size. So, e.g., you could have<br /><br />size 0.3, 1<br /><br />which will compress your image in the x direction by a factor of 3. You can also put all three images in the same figure as <br /><br />set multiplot<br />set size 0.3, 1<br />set origin 0,0<br /><br />plot something<br /><br />set origin 0.33, 0<br />plot something else<br /><br />set origin 0.66, 0<br />plot something else<br />unset multiplot<br /><br />The only thing you have to watch out for is the bounding box in the postscript file, if you want to produce that for a publication. Once you produced the figure, you should just open the postscript file, and set the bounding box by hand. It should be in the 6th line of the file, I believe. <br />Cheers,<br />ZoltánGnuplotterhttps://www.blogger.com/profile/10560778800525149384noreply@blogger.comtag:blogger.com,1999:blog-4020452510052679998.post-46389196991482960262010-02-21T06:25:24.828-08:002010-02-21T06:25:24.828-08:00Dear Gnuplotter,
just wanted to say that it is AW...Dear Gnuplotter,<br /><br />just wanted to say that it is AWESOME what you manage to create with Gnuplot!<br />I have tried to implement the plot with contours, adapted to my needs, and have encountered a problem: Apparently, when plotting with the image style, there is some trouble with logscales. Quite surprisingly, everything runs smoothly, as long as one does not tell Gnuplot specific plotting ranges, but if done, then the contours are properly plotted, not so the colour map...Any idea/suggestion why and how to fix it?<br /><br />Another (not related) question is about canvas orientation: Is it somehow possible to rotate the canvas (i.e. into a portrait orientation) so as to maximize the plotting area when plotting e.g. three figures on a column using multiplot?<br /><br />Thanks in advance, and especially for all the great tips!<br /><br />Thor.Unknownhttps://www.blogger.com/profile/03808705001785348203noreply@blogger.com