I'm new using gnuplot, today I learned a lot on stackoverflow for a problem that I had with a plot, but now for my research I need to do another one like the following image:
The data are of the same tipe, I collected them and isolate only the column that I need in a file.dat, and a sample is the following:
5.38e-51 1
2.75e-81 1
5.3e-67 1
8.71e-170 4
3.62e-59 3
2.98e-52 2
3.2e-31 1
2.98e-54 2
3.85e-29 2
5.38e-57 1
3.2e-33 2
2.75e-88 1
3.2e-34 1
9.89e-37 1
5.38e-59 2
3.2e-35 2
1.68e-168 1
1.81e-101 1
9.89e-39 1
2.98e-59 2
3.2e-39 1
1.07e-110 3
1.07e-111 2
1.81e-107 2
2.82e-40 4
2.6e-108 1
1.07e-115 1
My problem is that I would like on the x-axis that my x is the exponent, as 1E-x.
I tried using set format set format x '%.0f'.sprintf('e%d') but it doesn't work.
How can I do that?
thank you.
If you want to plot values which span many order of magnitudes you either plot it on logarithmic scale
or take log10() of your values and plot them in linear scale.
From your description without code and details, I'm guessing that you have
the data you've shown and want to create a histogram and display the negative log10 value on the x-axis.
NB: In your earlier data you had also 0.0, which will mess-up the smooth freq option together with the logarithmic bins. Note that set datafile missing "0.0" will only exclude 0.0 as text, i.e. 0, 0.00, or 0e-10 will not be excluded. So, make sure you don't have zeros in your data, this will not work with logarithmic scale.
Code:
### plot histogram with logarithmic bins
reset session
$Data <<EOD
5.38e-51 1
2.75e-81 1
5.3e-67 1
8.71e-170 4
3.62e-59 3
2.98e-52 2
3.2e-31 1
2.98e-54 2
3.85e-29 2
5.38e-57 1
3.2e-33 2
2.75e-88 1
3.2e-34 1
9.89e-37 1
5.38e-59 2
3.2e-35 2
1.68e-168 1
1.81e-101 1
9.89e-39 1
2.98e-59 2
3.2e-39 1
1.07e-110 3
1.07e-111 2
1.81e-107 2
2.82e-40 4
2.6e-108 1
1.07e-115 1
EOD
set xlabel "-log_{10}(x)"
set xrange[-15:200]
set xtics 10 out
set ylabel "Sequences"
set yrange [0:]
set key noautotitle
# Histogram with logarithmic bins
BinWidth = 10
Bin(x) = floor(-log10(x)/BinWidth)*BinWidth + BinWidth*0.5
set boxwidth BinWidth
set style fill solid 0.3
set offset 1,1,1,0
set grid x,y
set datafile missing "0.0" # exclude zero, otherwise it will mess up "smooth freq"
plot $Data u (Bin($1)):2 smooth freq with boxes lc "red"
### end of code
Result:
Related
Can you tell me how to specify the default cb (or z) value?
I build a 3d chart {x,y,z} or {x,y,cb}, but for different x there are different ranges of y, and as a result white bars are visible on the chart (for heatmap/colorbox). I would like to see no white stripes, and where there is no data, gnuplot would substitute the default value (for example, 0) and, accordingly, paint the field with the appropriate color for heatmap
You have several options, depending on exactly what plot mode you are using and what type of data you have. In general you can use two properties of the color assignment to get what you want:
1) out-of-bound values are mapped to the color of the extreme min or max of the colorbar. So one option is to assign a palette that has your desired "default" color at the min and max, independent of whatever palette function you use for the rest of the range
2) data values that are "missing" or "not-a-number" generally leave a hole in the grid of a pixel image or heat map that lets the background color show through.
There is a demo imageNaN.dem in the standard demo set that shows use of these features for several 2D and 3D heat map commands. The output from a heatmap generated by splot $matrixdata matrix with image is shown below.You can see extreme values pinned to the min/max of the colorbar range.
Note that if you want some color other than the backgroundn to show through, you could position a colored rectangle behind the heat map surface.
# Define the test data as a named data block
$matrixdata << EOD
0 5 4 3 0
? 2 2 0 1
Junk 1 2 3 5
NaN 0 0 3 0
Inf 3 2 0 3
-Inf 0 1 2 3
EOD
set view map
set datafile missing '?'
unset xtics
set ytics ("0" 0.0, "?" 1.0, "Junk" 2.0, "NaN" 3.0, "Inf" 4.0, "-Inf" 5.0)
set cblabel "Score"
set cbrange [ -2.0 : 7.0 ]
splot $matrixdata matrix using 1:2:(0):3 with image
#Ethan, I really don't have some data, which results in white slits.
I can fill in the missing data 0 at the stage of forming the data file, but then some files become very large and gnuplot spends all the memory.
So I'm looking for a way to solve the problem.
My example:
For #Ethan: my code:
set arrow from 0,86400 rto graph 1, graph 0 nohead ls 5 front
#===> decision of problem
set object rectangle from graph 0, graph 0 to graph 1, graph 1 behind fc rgbcolor 'blue' fs noborder
set pm3d map
# set pm3d interpolate 32,32
set size square
set palette rgbformulae 22,13,-31
splot inputFullPath u 2:1:(percentage($4)) notitle
and my data (for example):
0 1 0.1
0 2 0.2
0 4 0.5
# -------- {0,5..7} - white gap
# -------- {1,1..3} - white gap
1 3 0.6
1 4 0.5
1 7 0.9
Considering the data (in file, test.txt):
i x(volts) y(amp)
0 1 5
1 2 6
2 3 7
3 4 8
4 5 3
5 5 4
If I do:
set key autotitle columnheader
plot "test.txt" using 1:2
Then I get:
And, if I do:
set xlabel "x(volts)"
set ylabel "y(amp)"
plot "test.txt" using 1:2
Then I get
In the first case I read the label from file but it went into the legend. In the second case I set the x y labels but not reading from file.
How do I set x y labels reading from file?
You can use system command to get output of the external program into variable.
s=system('head -n 1 test.txt')
set xlabel word(s,2)
set ylabel word(s,3)
plot 'test.txt' u 1:2
I would like to plot these data
1 2
2 3
3 5
4 5
5 6
with this code
set ter pdfcairo enhanced color solid
set out "test.pdf"
set xrange [-.5:4.5]
set yrange [.5:6.5]
unset key
plot "test.txt" u 0:1,"" u 0:2, "" u 0:1:(0):($2-$1) with vectors nohead lw 0.5
The line width command seems to work, but it seems not to work with a line width smaller than 1.
this plot is with line width 5:
this plot is with line width 1
this plot is with line width 0.2
as one may notice, there is no difference between the latter two plots. How can I force gnuplot to use a line width smaller than 1?
How can I make clustered rowstacked bars in gnuplot? It know how to get a clustered bars, but
not a cluster of rowstacked bars. Thanks!
Edit: in a cluster, stacked bars should use different colors/patterns as well.
I'm not completely sure how to go about doing this, but, one idea is to make it so that the boxes are touching each other
`set boxwidth 1`
That doesn't quite get you a "clustered" look yet -- To get a clustered look, I think you'd need to insert a row (maybe column) of zeros...(I haven't sorted through that one in my head yet) into your datafile where you want a cluster break.
Of course, you wouldn't need to set the boxwidth either I suppose...clustered just depends on the breaking every once in a while...
If I understand the original post right, it should be easy to accomplish with gnuplot if you can preprocess your data to offset x coordinates of specific data series.
To illustrate the approach I will use the following data in 3 data series:
# impulse.dat
0.9 1
1.9 4
2.9 3
3.9 5
1.0 1
2.0 2
3.0 4
4.0 2
1.1 3
2.1 3
3.1 5
4.1 4
Here each series has x-coordinates shifted by .1. To plot it I choose impulses of width 10.
plot [0:5] [0:6] 'impulse.dat' ind 0 w imp lw 10, \
'impulse.dat' ind 1 w imp lw 10, \
'impulse.dat' ind 2 w imp lw 10
Edit: to combine this with Matt's suggestion to use boxes would definitely be better:
set boxwidth 0.1
set fill solid
plot [0:5] [0:6] 'impulse.dat' ind 0 w boxes,\
'impulse.dat' ind 1 w boxes, \
'impulse.dat' ind 2 w boxes
Following is the picture with impulses.
I am trying to use R to make an excel kind of a line plot, where my x axis is text (A,B,c..etc) and the y axis(which can be both negative and positive) are up and down columns. I want to give up a red color and down green.
I would really appreciate if anyone can help me regarding this. I have plotted this in excel but i have thousands of rows in my data and excel doesnot show all the text point in my plot.
My data looks like the following:
Name UP Downs
A 10 -3
B 2 -4
C 1 -1
D 4 -1
E 5 0
F 0 -1
G 6 -5
H 0 -1
I 7 -1
J 0 -1
K 0 -11
L 3 -1
M 0 -13
N 2 -1
O 0 -1
P 1 -1
Q 0 0
R 1 -1
S 0 0
T 12 -1
This is probably not the most elegant way to do it, but you can work it all out using with plot, points, and axis (axis is the main one, it explains how you can change the labels on the axis): ?axis, ?plot, ?points.
First make a data frame similar to yours so I can demonstrate...
# make a data frame similar to yours
mydf <- data.frame( Name=LETTERS,
Up=sample.int(15,size=26,replace=T),
Down=-sample.int(15,size=26,replace=T) )
Now plot.
# set up a plot: x axis goes from 1 to 26,
# y limit goes from -15 to 15 (picked manually, you can work yours out
# programmatically)
# Disable plotting of axes (axes=FALSE)
# Put in some x and y labels and a plot title (see ?plot...)
plot(0,xlim=c(1,26),ylim=c(-15,15),type='n',
axes=FALSE, # don't draw axis -- we'll put it in later.
xlab='Name',ylab='Change', # x and y labels
main='Ups and Downs') #,frame.plot=T -- try if you like. ?plot.default
# Plot the 'Up' column in green (see ?points)
points(Up~Name,mydf,col='green')
# Plot the 'Down' column in red
points(Down~Name,mydf,col='red')
# ***Draw the x axis, with labels being A-Z
# (type in 'LETTERS' to the prompt to see what they are)
# see also ?axis
axis(1,at=1:26,labels=LETTERS)
# Draw the y axis
axis(2)
Tweak it as you wish: ?points and ?par and ?axis are particularly helpful in this respect.