I want to plot a histogram like chart with boxes. And I hope the bars have different colors. I found some previous cases, use lc rgb variable, but it doesn't work for me. My version is limited to gnuplot4.2. Here is my data sheet:
stage 11402.364 100% 1
App1 78.552 0.69% 2
App2 11323.812 99.30% 2
Read 8.469 0.07% 3
Write 41.285 0.04% 3
Repeat 5748.351 50.41% 3
Count 4933.746 43.27% 3
Count_1 3841.355 33.69% 4
Count_2 1092.391 9.59% 4
Here is the code part:
set boxwidth 0.5 relative
set style fill solid 0.5
set xtics rotate
plot 'histogramdata_2.txt' using 2:xtic(1):4 with boxes variable lc rgb variable notitle
I want to use the 4th column to denote the bar color. The document said the third number used in using is just the color variable. But it doesn't work for me, the result is no bar produced.
It seems that the using part is quite flexible. I even find some cases in this site put 4 column numbers after using.
It is related to different versions?
Your plot command seems to be wrong. Try the following:
set boxwidth 0.5 relative
set style fill solid 0.5
set xtics rotate
plot 'histogramdata_2.txt' using 0:2:4:xticlabels(1) with boxes lc variable
It should look like this:
In short about the using 0:2:4:xticlabels(1) part:
0 tells gnuplot to place bars (x value) in the same order as they appear on the file
2 tells gnuplot to take y values from column 2
4 tells gnuplot to take the color variable from the 4th column
xticlabels(1) tells gnuplot to take the text labels for the bars from column 1
Related
I looked for an answer to this question but wasn't able to find one that exactly matched with my particular problem.
First of all, I am using gnuplot (since I haven't found this answer also using Julia...)
The issue:
I have a file (test.dat) which is basically an array. It has 100 rows and 50 columns. Each row represents a bar chart that I need to plot. IN each column of that row, there is the value or magnitude of the bar. Simple.
So I need to plot all rows (a total of 100 bar charts) in the same graph. Also, I need it to be with transparency, so I can see all the bar-charts.
Can anybody help me with this problem?
You use this to set transparency:
set style fill transparent solid 0.5
0.5 is the level of transparency.
But if I understood the question correctly, your data format may be problematic. With the following data:
1 10 50
2 20 40
3 30 30
4 40 20
5 50 10
so 2 charts, each with 5 elements, and the following gnuplot instructions:
set terminal pngcairo truecolor size 800, 600
set output "data.png"
set style fill transparent solid 0.5
set style data boxes
set boxwidth 0.5
plot 'data.txt' using 1:2 title 'foo' linetype rgb 'red', \
'' using 1:3 title 'bar' linetype rgb 'web-blue'
you will get this:
I am executing the following gnuplot script:
set terminal svg
set output "file.svg"
set yrange [0:1]
set style fill solid
set key top left
set style fill transparent solid 0.6 border lt -1
set palette model RGB defined (1 "red", 2 "blue")
set xtics rotate by -45
plot "file.data" using 3:xticlabels(2):1 title "" with boxes palette
and file.data looks like this:
1 name1 0.356877
1 name2 0.643123
2 name3 0.688312
2 name4 0.311688
So I want the boxes with leading 2's in the data file to be blue, and the ones with a 1 in front to be red.
It fails when I add the palette keyword and prints the error message in the title.
Gnuplot is v4.6 patchlevel 4, I am running it on Ubuntu 14.04. I have created coloured plots this way before, so this probably is just a tiny error I am overlooking, but I'm all out of ideas.
Your script has two errors:
incorrect format specifier
According to the gnuplot documentation (? boxes at the command line) if three columns of input are provided to plot with boxes, the third column is a width parameter for the boxes. Using a variable line/fill color requires adding an additional column of input:
plot "file.data" using 0:3:(1):1 with boxes
An explanation of the four columns:
Column 0 provides an index: the first is 0, second is 1 etc. These give the x position (assuming each box is an individual).
Column 3 is your y data.
Column (1) provides the numerical value 1 for the x width of your boxes.
Column 1 provides your color information.
missing lc (linecolor) parameter to plot command
Your whole plot command should look like
plot "file.data" using 0:3:(1):1 title "" with boxes lc palette
also note
Keep in mind that the palette information is rescaled to be between the min/max values of cbrange. What I mean is that if your data is binary (1 or 2 in this case) the palette will be constructed properly, but if you want more specific colors (e.g. for data values 1/2/3) and you set a three-color palette in the same way it may not work the way you expect.
I have several files that I would like to plot in 2D without interpolation (i.e. a heat map). The data is in three columns (not as a matrix):
#Example data
0 0 1
0 1 -1
0 2 10
1 0 -2
1 1 -0.1
1 2 20
I am using the following commands (Version 4.4):
set pm3d map
set palette rgbformulae 22,13,-31
plot "file" us 1:2:($3>=0?0:$3) notitle w image
which produces the following image:
However, what I would like is:
Ensure that all (column 3) values less than zero will follow the color palette
Ensure that all (column 3) values greater than or equal to zero are white
The color bar does not contain white
I want the image to look like this:
Note, that this is only an example. In my real data, the values that are greater than or equal to zero are dispersed throughout the data. I've been playing around with this all morning but have yet to come up with a solution. Any suggestions would be greatly appreciated.
This is achieved by setting those values to NaN:
set view map
set palette rgbformulae 22,13,-31
plot "file" us 1:2:($3>=0?NaN:$3) notitle w image
This method works only with some terminals (see the discussion at Transparency for specific values in matrix using Gnuplot while preserving the palette?): It works at least with wxt, pdfcairo, pngcairo and png. It does not work with at least x11 and postscript.
The result with 4.6.3 is:
I'm trying to create a simple histogram of events per month over a 12 month year in Gnuplot. There are no events in either bin 2 or bin 7 and rather than plotting those bins as 0 it extends the neighboring bins over this space. I am using the following histogram plotting routine, which I've gotten from here: http://gnuplot-surprising.blogspot.com.au/2011/09/statistic-analysis-and-histogram.html
max=12
min=1
binwidth=1
hist(x,width)=x
set style fill solid 0.5
set xrange[0.5:12.5]
plot "file" using (hist($4,binwidth)):(1.0) smooth freq w boxes lc rgb"green"
where a sample row from "file" looks like this:
2008-11-21-08:10:47 29455.0 2008 11 21 19:10:47
The fourth column is the month information I am trying to plot. The resulting histogram is at the link:
https://docs.google.com/drawings/d/12yFs_KIznhrMx62OIwJJFVmlnwIk4TXdHSdGc0yWqwI/edit?usp=sharing
The bins centered on 2 and 7 (that should be 0) are missing and the neighboring bins are extended instead. I'm not sure where my error is and would appreciate any help! Thank you!
You should consult the gnuplot documentation about the boxes plotting style. Use
set boxwidth 1
otherwise the width of each box is caculated automatically so that it touches the adjacent boxes.
Can I get gnuplot to display the exact y-value or height of a data point (plotted using "with boxes") over its bar? I would like the plot to be easy to read so nobody has to line up the top of a bar with the y-axis and guess what the value is.
You can use the labels style and combine it into the plot command with the boxes style. The labels style expects 3 columns of data - the x coordinate, the y coordinate, and the actual label text.
For example, with the following data
1 4
2 6
3 2
4 8
the command (we set the yrange to 0 - 10 and boxwidth to 0.9 and set a solid fill style)
plot datafile u 1:2 with boxes, "" u 1:2:2 with labels offset char 0,1
produces
Normally, the labels would be centered on the specified point (the top edge of the box). By specifying an offset, we can move them up to just above the box. Here we used no offset in the x direction, but a unit of 1 in the y direction. We used the character coordinate system, so this corresponds to moving up by one character unit.
I can only think of putting the values where you want them "manually" like this:
set label "value" at 12,34
The numbers are coordinates according to your x and y ranges.
An automatic way would use "with labels", see e.g.
http://gnuplot.sourceforge.net/demo_4.4/stringvar.html