Is this possible in gnuplot?
How more energie how harder the color, look the example.
plot for [i=1:16] file u 1:($10/i):((i*2)*1048576) w boxes lc rgb variable notitle.
This is what I have now, this might be a possibility? The first example was an Excel graph.
Finaly i have for me the perfect, and . . i think a very nice solution.
First the plot and after that the correspondenting script.
The highlights are;
maks = STATS_max_y
min = STATS_max_x
afgenomen = gebruikt-zon
set palette defined (-(min) "#D30000", 0 "#00F000", .1 "#FFF900", (maks) "#FF0700")
plot for [i=51:1:-1] file u 1:(($10/51)*i):(($10/51)*i) w boxes lc palette notitle,\
file u 1:10 w boxes fill empty notitle,\
For all the examples that i have made look on my site: http://ccvd.eu/Energie.html
Related
I am trying to plot a data (x, y, z) in gnuplot of range x=(0, 50k+) , y=(0,50k+).
However, the data need to be super imposed on a map which is of size (2000, 2000).
The issue I am having is, the x and y axis range is 50k+ and the data is plotting nicely,
however, the image is rendered in a corner mapping the (0, 2000) range in axis.
I need to render the map independent of the data axis comprising the whole plot area,
over the ata range. Following is what I am trying that doesn't scale the image,
reset
set dgrid3d 200,200 qnorm 2
set xrange [0:57599]
set yrange [0:57599]
set table $Data
splot "data.dat" using 1:2:4
unset table
# create contour lines
set contour base
set cntrparam level incremental 0, 5, 100
unset surface
set table $Contour
splot "data.dat" using 1:2:4
unset table
unset key
set palette defined ( 0 "#ff0000", 40 "#0000ff", 60 "#00ff00", 100 "#e0e0e0" )
set size square
set style fill transparent solid 0.4 noborder
plot "Map.png" binary filetype=png w rgbimage, \
$Data u 1:2:(6):(6):3 with boxxyerror palette,\
$Contour u 1:2:3 w l lt rgb "grey"
This is what I am getting,
this is what I am trying to do,
There are auxilliary keywords that can modify binary filetype=png w rgbimage. The ones you want are dx and dy (see "help binary keywords"). In your case the image is 2000x2000 pixels and each pixel represents an area
57599/2000 = 28.8, so the plot command becomes
plot "Map.png" binary filetype=png dx=28.8 dy=28.8 with rgbimage, \
$Data u 1:2:(6):(6):3 with boxxyerror palette,\
$Contour u 1:2:3 w l lt rgb "grey"
If necessary, you can adjust the image placement relative to the origin of the plot using the keyword origin=(x0,y0)
Alternative answer if you are using the current version (5.4) of gnuplot
Instead of drawing your map as part of the plot command with rgbimage, you can place it as a pixmap filling the plot area and then draw your plot on top of it. The syntax for that would be:
set pixmap 1 "Map.png" at graph 0,0 size graph 1,1 back
plot $Data u 1:2:(6):(6):3 with boxxyerror palette,\
$Contour u 1:2:3 w l lt rgb "grey"
However this loses any connection between the coordinates of the map and the plot, so it is entirely up to you to make sure they match. For example if you zoom the above plot, the zoomed plot will contain a subset of the original data and contours but the entire map image will still be used to fill the plot area. In the solution using with rgbimage, the map and the contours would all zoom together.
Is it possible in Gnuplot to emulate the drawing style of an analogue oscilloscope, meaning thinner+dimmisher lines on larger amplitudes, like this:?
The effect you see in the oscilloscope trace is not due to amplitude, it is due to the rate of change as the trace is drawn. If you know that rate of change and can feed it to gnuplot as a third column of values, then you could use it to modulate the line color as it is drawn:
plot 'data' using 1:2:3 with lines linecolor palette z
I don't know what color palette would work best for your purpose, but here is an approximation using a function with an obvious, known, derivative.
set palette gray
set samples 1000
plot '+' using ($1):(sin($1)):(abs(cos($1))) with lines linecolor palette
For thickness variations, you could shift the curve slightly up and down, and fill the area between them.
f(x) = sin(2*x) * sin(30*x)
dy = 0.02
plot '+' u 1:(f(x)+dy):(f(x)-dy) w filledcurves ls 1 notitle
This does not allow variable colour, but the visual effect is similar.
Another approach:
As #Ethan already stated, the intensity is somehow proportional to the speed of movement, i.e. the derivative. If you have sin(x) as waveform, the derivative is cos(x). But what if you have given data? Then you have to calculate the derivative numerically.
Furthermore, depending on the background the line should fade from white (minimal derivative) to fully transparent (maximum derivative), i.e. you should change the transparency with the derivative.
Code:
### oscilloscope "imitation"
reset session
set term wxt size 500,400 butt # option butt, otherwise you will get overlap points
set size ratio 4./5
set samples 1000
set xrange[-5:5]
# create some test data
f(x) = 1.5*sin(15*x)*(cos(1.4*x)+1.5)
set table $Data
plot '+' u 1:(f($1)) w table
unset table
set xtics axis 1 format ""
set mxtics 5
set grid xtics ls -1
set yrange[-4:4]
set ytics axis 1 format ""
set mytics 5
set grid ytics ls -1
ColorScreen = 0x28a7e0
set obj 1 rect from screen 0,0 to screen 1,1 behind
set obj 1 fill solid 1.0 fc rgb ColorScreen
x0=y0=NaN
Derivative(x,y) = (dx=x-x0,x0=x,x-dx/2,dy=y-y0,y0=y,dy/dx) # approx. derivative
# get min/max derivative
set table $Dummy
plot n=0 $Data u (d=abs(Derivative($1,$2)),n=n+1,n<=2? (dmin=dmax=d) : \
(dmin>d ? dmin=d:dmin), (dmax<d?dmax=d:dmax)) w table
unset table
myColor(x,y) = (int((abs(Derivative(column(x),column(y)))-dmin)/(dmax-dmin)*0xff)<<24) +0xffffff
plot $Data u 1:2:(myColor(1,2)) w l lw 1.5 lc rgb var not
### end of code
Result:
I am trying to make a barplot with GNUplot, were each bar has a different color. I have found out in the manual that it can be done using lc rgbcolor variable.
My data folder looks like this,
ACB 0.106372
ASW 0.10909
BEB 0.110973
CDX 0.106577
CEU 0.102091
CHB 0.108829
CHS 0.110807
CLM 0.108803
My plot script is as follows,
set style histogram gap 2
set autoscale y
set style fill solid
set xtics rotate by 90 offset 0,-1.2
rgb(r,g,b) = 65536 * int(r*10) + 256 * int(g*10) + int(b*10)
set boxwidth .5
set output "Plot.eps"
plot "plot.tsv" using 2:xticlabels(1):(rgb($2,$2,$2)) with boxes lc rgb variable
I have used the rgb function that is shown in the GNUplot manual. But it shows the following error.
plot "plot.tsv" using 2:xticlabels(1):(rgb($2,$2,$2)) with boxes lc rgb variable
^
"#Plot.plt", line 18: x range is invalid
I can't figure out what the error means.
Please help.
Thanks in advance.
You are actually plotting with style "boxes", not "histograms". That probably is what you want, but whereas for histograms the x coordinate is implicit, for boxes you have to provide an x coordinate in the first column even if you're OK with the ordinal numbers 0,1,2,3,...
So
plot "plot.tsv" using 0:2:xticlabels(1):(rgb($2,$2,$2)) with boxes lc rgb variable
Oh, and you probably want to set the fillstyle also so that the colors are visible:
set style fill solid
I am trying to plot a graph and fitting it using a linear line.
f1(x)=a1+b1*x
fit [0:80] f1(x) 'diff-xy-bcmLyo25perS.dat' via a1,b1
f2(x)=a2+b2*x
fit [100:220] f2(x) 'diff-xy-bcmLyo25perS.dat' via a2,b2
And I tried to plot both the plots into the same graph using command:
f(x) = x < 60 ? f1(x) : f2(x)
plot 'diff-xy-bcmLyo25perS.dat' using 1:2 with lines linestyle 1 title "{/Symbol b}BCMal-C_{12}C_{8}", f(x) lw 3.0 lc rgb 'black'
I get a plot as above.
In that plot one could see that there are two lines intersecting at 80 (horizontal scale) and it makes shape like 'v'.
I wish to eliminate that 'v' shape intersection and I would like to get two separate lines, one from 0 to 80 and the other one from 100 to 220.
How I could get this?
Appreciate any help.
Thanks in advance.
You could exploit that gnuplot doesn't plot infinity and NaN values (as 1.0/0)
Using
plot_if_in_range(y,x,lower,upper) = (x>=lower && x<=upper)?(y):(1.0/0)
You could easily plot any function in given domain:
plot plot_if_in_range(exp(x) , x, -5, 2), \
plot_if_in_range(sin(x)+x, x, -2, 5)
With gnuplot 5.0 you can specify different range for different functions:
set style data lines
plot 'diff-xy-bcmLyo25perS.dat' using 1:2 ls 1, \
[0:80] f1(x) lw 3.0 lc rgb 'black',\
[100:220] f2(x) lw 3.0 lc rgb 'black'
Note, that this works only, because you first plot the data file. Plotting only
plot [0:80] f1(x), [100:220] f2(x)
wouldn't work, since the first range settings are equivalent to a global set xrange [0:80] (it has always been), so that the second function wouldn't be visible at all.
However, in your case it should work fine.
Edit:
Sorry, this is basically the same idea as Sergei Izmailov's answer which I missed.
Answer:
Use the special file "+", which provides x values for your plot that you can then sample using a function of your choice, including one that ignores input if it's outside of range. Then you can use your f1(x) and f2(x) directly:
plot "+" using ($1):(0 < $1 && $1 < 80 ? f1($1) : 1/0), \
"+" using ($1):(100 < $1 && $1 < 220 ? f2($1) : 1/0)
I have a data file, with column 1 as the independent variable and columns 2 and 3 as dependent variables. I want to plot variables 2 and 3 on different y axes using something like this:
plot "file.out" u 1:2 axes x1y1, "file.out" u 1:3 axes x1y2
When I do this, the "0" for both axes are offset from one another. How can I fix the zero of one y-axis to the zero of the other y-axis, without explicitly setting yrange to be symmetric for both quantities?
It is possible form version 5 to use set link. However it does not autofit the ratios, so you're left with calculating them yourself
stat "file.out" u 1:2
MAX1=abs(STATS_max_y)
MIN1=-abs(STATS_min_y)
stat "file.out" u 1:3
MAX2=abs(STATS_max_y)
MIN2=-abs(STATS_min_y)
min(a,b)=(a<b)?a:b
set link y2 via min(MAX1/MAX2,MIN1/MIN2)*y inverse y/min(MAX1/MAX2,MIN1/MIN2)
plot "file.out" u 1:2 axes x1y1, "file.out" u 1:3 axes x1y2
Here is a solution which works without linking axes, hence it also works even with gnuplot 4.4 (the version from 2010).
Although, it doesn't need stats but as a disadvantage it requires to replot the data to get the proper scaling of the y2-axis.
Code:
### aligning zero on y1- and y2-axes
reset
set ytics nomirror
set y2tics nomirror
set xzeroaxis
set key top left
plot \
sin(x) axes x1y1 w l, \
cos(x)-0.5 axes x1y2 w l
R0 = -GPVAL_Y_MIN/(GPVAL_Y_MAX-GPVAL_Y_MIN)
y2_min_new = abs(GPVAL_Y2_MIN)>abs(GPVAL_Y2_MAX) ? GPVAL_Y2_MIN : R0*GPVAL_Y2_MAX/(R0-1)
y2_max_new = abs(GPVAL_Y2_MAX)>abs(GPVAL_Y2_MIN) ? GPVAL_Y2_MAX : (R0-1)*GPVAL_Y2_MIN/R0
set y2range[y2_min_new:y2_max_new]
replot
### end of code
Result:
Unfortunately, you can't (at least not in general). If the yrange has the same percent above and below 0, it should probably work, e.g.:
set yrange [-5:10]
set y2range [-10:20]
But if you don't want to do that, then I don't know that there's a better solution...