Assume we have a 5x4x3 3D grid, where each cell has a value:
0.5523 0.0495 0.1465 0.5386
0.6299 0.4896 0.1891 0.6952
0.0320 0.1925 0.0427 0.4991
0.6147 0.1231 0.6352 0.5358
0.3624 0.2055 0.2819 0.4452
0.1239 0.2085 0.9479 0.6210
0.4904 0.5650 0.0821 0.5737
0.8530 0.6403 0.1057 0.0521
0.8739 0.4170 0.1420 0.9312
0.2703 0.2060 0.1665 0.7287
0.7378 0.8589 0.1339 0.3329
0.0634 0.7856 0.0309 0.4671
0.8604 0.5134 0.9391 0.6482
0.9344 0.1776 0.3013 0.0252
0.9844 0.3986 0.2955 0.8422
How can I achieve a plot in gnuplot that is similar to this plot achieved in matlab using patch? Note that the grid cells has an alpha value of 0.8.
Related
I'm plotting an animated surface in gnuplot and want to read in an average or sum of the mapped z values and include this in a label to be printed in the plot, so that I get a running total updated as the GIF progresses. It's probably straightforward, but I'm a "gnu"bie, so to speak, and find this system pretty confusing!
I've tried putting the running sum and average numbers in additional columns ...
splot 'output3.dat' index i:i using 1:2:(column(3), TD1 = strcol(4), TD2 = strcol(5)) with pm3d
but this doesn't plot, and the string variables TD1, TD2 don't seem to exist outside the splot command.
The command you show would indeed set variables TD1 and TD2 globally if you change the order of clauses in the serial evaluation expression (the comma-separated sub-expressions):
splot 'output3.dat' index i:i using 1:2:(TD1 = strcol(4), TD2 = strcol(5), column(3)) with pm3d
However, if the idea is to create a label using set label that will appear as part of the resulting graph, this won't work. The set label command would have to be executed before the splot command, so TD1 and TD2 will not have the correct values yet.
There is an alternative that might serve you better. Instead of trying to put this dynamically evaluate information in a label, put it in the plot title. Unlike a label, the plot title is evaluated after the corresponding plot is generated, so any variables set or updated by that plot will be current. [caveat: this is true for current gnuplot (version 5.4) but was not always true. If you have an older gnuplot version the title is evaluated before the plot rather than after].
Since current gnuplot also allows you to place the individual plot titles somewhere other than in the key proper, you have the same freedom that you would with a label to position the text anywhere on the output page. For example, if you want to sum the values in column 3 of the data file and print the total as part of a title above the resulting plot:
SUM = 0
splot 'foo.dat' using 1:2:(SUM = SUM+column(3), column(3)) with linespoints title 'foo.dat', \
keyentry title = sprintf("Points sum to %g", SUM) at screen 0.5 0.9
I used a separate keyentry clause because this allows to omit the sample line segment that would otherwise be generated, but it would also be possible to make this the title of the plot itself if you want that sample line.
I have a problem with gnuplot.In my data there is a very obvious linear relation in a specific range. So I want to do a linear fit in that range. But gnuplot throws something like an orthogonal (to as it should be) out.
I created the following fitting-file:
set fit errorvariables
f(x)=a*x+b
fit f(x) 'Data1f.txt' using 1:2:3:4 xyerrors via a,b
g(x)=c*x+d
fit g(x) 'Data2f.txt' using 1:2:3:4 xyerrors via c,d
set xlabel 'U_G [V]'
set ylabel '{/Symbol=\326}(U_{Ph}-U_0) [{/Symbol=\326}U]'
set xrange [0:0.9]
set yrange [0:4.5]
set grid
plot 'Data1.txt' using 1:2:3:4 w xyerrorbars title 'Measurement 1', f(x) title 'f(x)', 'Data2.txt' using 1:2:3:4 w xyerrorbars title 'Masurement 2', g(x) title 'g(x)'
And it results in the following plot:
I don't know why it is not fitting the obviously linear part of the Data ('Data1f' and 'Data2f' contain exact the same values like 'Data1' and 'Data2' just with some data-points left out. (i tried that when the range comands 'fit [number:number] f(x)......' showed the same result.).
Even LibreOffice Calc was able to give me a fitting curve that resulted in the expected one (but LibreOffice Calc can't handle errors - only the data-points itself).
Because you specified the range after fitting, gnuplot fits the linear function to the full data set, which you said is non-linear. Therefore the result is obviously bad. If you change the order of your commands, fit will only use in-range data and you should get a reasonable fit:
set xrange [0:0.9]
set yrange [0:4.5]
fit f(x) 'Data1f.txt' using 1:2:3:4 xyerrors via a,b
fit g(x) 'Data2f.txt' using 1:2:3:4 xyerrors via c,d
You initialize a,b,c, and d with some value nearby that you are expecting. Then try it, it will work. Initially, the value may be some random garbage number and I could fix the same problem by Initializing the constants with some expected nearby values
I have dictionary as:
```{'0.0': 2.445616223564293,
'0.05': 2.445594095119315,
'0.1': 2.4455740588234223,
'0.15': 2.4455560866270947,
'0.2': 2.4455401509059596,
'0.25': 2.4455262244535803,
'1.0': 2.4455411399961293,
'1.05': 2.44555597697399,
'1.1': 2.4455724183134344,
'1.15': 2.4455904432448716,
'1.2': 2.445610031303073,
'1.25': 2.4456311623222002,
'2.0': 2.4461204322901566,
'3.0': 2.447205696789686,
'4.0': 2.4486856713473726,
'5.0': 2.4504762863004363,
'10.0': 2.4623061878090624,
'20.0': 2.4922549001247876}```
Here all the values are different by some small factor. However when I plot it using matplotlib the plot is not distinctive.
I want to plot "keys" in x-axis and "values" in y-axis and then find x which has minimum y value by looking the plot.
I tried this code:
```plt.plot(*zip(*data))```
But the plot is not clear. How can I solve this problem such that plot is clearly able to show the difference in values.
The problem is your interpretation of zip(*data). I would suggest before plotting you first print and see what you are trying to plot.
print (list(zip(*data))) would print a list of splitted strings (keys of your data). To plot the keys on the x-axis and the values of the y-axis, simply do the following. I leave the visualization of the minimum up to you. If you want to plot the difference, subtract the first value from the complete list of values and then plot it on the y-axis.
plt.plot(data.keys(), data.values(), '-bx')
plt.xticks(rotation=45)
My question is about my code in gnuplot. I want to plot data with pm3d map and Matrix and want to plot the z value in each datapoint as well. I tried this:
set pm3d;set pm3d interpolate 0,0;set pm3d map;
set Palette rgb 33,13,10;splot 'filepath' Matrix
It is all working fine but I cannot plot the z values so I tried this one
splot 'filepath' Matrix using 1:2:(sprintf(%g,$3)) with labels
but this is also not working. Can anybody help me?
as #Bodo, wrote... "not working" is not enough and not helpful to others.
With your code, you must have gotten some error messages, provide them as well.
Several mistakes in your script:
set palette instead of set Palette
splot 'filepath' matrix instead of splot 'filepath' Matrix
sprintf("%g",$3) instead of sprintf(%g,$3)
To your actual problem:
splot requires 3D coordinates + label text, i.e. in your case x:y:z:z or 1:2:3:3
So, the following code is probably doing what you intended to do.
set pm3d
set pm3d interpolate 0,0
set pm3d map
set palette rgb 33,13,10
splot 'filepath' matrix u 1:2:3:(sprintf("%g",$3)) with labels
I am trying to use the layered methods to overlay few spatstat spatial objects. All these objects are for the same window. I have an im layer (density) from a ppp. I want to make this layer a bit transparent in order to have a better visibility of the other objects in the layered object.
How can I control the transparency of this density plot (im)? Is there something like alpha or transparency parameter for the plot.im ?
UPDATE:
library(spatstat)
pipes=simplenet
plot(pipes)
point_net = as.ppp(runifpoint(10, win = Window(pipes)))
point_surface = density(point_net)
plot(point_surface)
layers= layered(point_surface, point_net, pipes)
plot(layers)
Here , I have plotted 3 layers. As you can see the density plot has very dark blues and reds. Yes, I can plot lines and points with different colours to make them visible, but it would nice to do simple stacked line, point plots and add a little bit of transparency to the density (im) plots.
The purpose is just to avoid complex customized plot colours and to explain to colleagues.
thank you.
First the commands from the original post:
library(spatstat)
pipes=simplenet
point_net = as.ppp(runifpoint(10, win = Window(pipes)))
point_surface = density(point_net)
layers= layered(point_surface, point_net, pipes)
plot(layers)
You need to provide a different colourmap to plot.im. There are two
ways you can do this:
Plot each layer individually using add = TRUE for subsequent
layers and provide the colour map when you plot the im object.
Pass a list of plot arguments when you plot the layered object you
have created above.
I find the first option easier for illustration, so I will do that
first. The default colourmap of spatstat is the 29th Kovesi colour
sequence (?Kovesi for more details on these sequences):
def_col <- Kovesi$values[[29]]
head(def_col)
#> [1] "#000C7D" "#000D7E" "#000D80" "#000E81" "#000E83" "#000E85"
To add transparency you can use to.transparent with your choice of
fraction for more/less transparency:
def_col_trans <- to.transparent(def_col, fraction = 0.7)
head(def_col_trans)
#> [1] "#000C7DB3" "#000D7EB3" "#000D80B3" "#000E81B3" "#000E83B3" "#000E85B3"
Now you just need to use this as your colourmap:
plot(point_surface, col = def_col_trans)
plot(point_net, add = TRUE)
plot(pipes, add = TRUE)
To do it with the layered object you have to make a list of plot
argument lists (containing NULL if you don't have additional
arguments):
layer_args <- list(list(col = def_col_trans),
list(NULL),
list(NULL))
plot(layers, plotargs = layer_args)