Showing posts with label transparency. Show all posts
Showing posts with label transparency. Show all posts

Sunday, September 18, 2011

transparency in gnuplot

There is options to set the fill color in gnuplot to be transparent. But some friends of mine ofen complained that it never works. This is because to let the transparency really work, you also need to choose a transparency supported terminal type. For raster graphics "png" may be a choice, and for vector graphics it may be "pdf". You can use command "help transparent" to see the details.
There is an example.
reset
f(v,T)=4/sqrt(pi*T**3)*exp(-v**2/T)*v**2
set sample 500
set title "Maxwell speed distribution"
set xlabel "Speed [(2kT_c/m)^{1/2}]"
set ylabel "Probability Intensity f(v)"
set style fill transparent solid 0.5
set key Left
set term png truecolor enhanced font "Times,15"
set output "maxwell_speed_distribution.png"
plot [0:5] f(x,0.1) w filledcurves x1 title "T=0.1T_c",\
           f(x,1)   w filledcurves x1 title "T=T_c",\
           f(x,5)   w filledcurves x1 title "T=5T_c"
set term pdf enhanced
set output "maxwell_speed_distribution.pdf"
replot
Note that when transparency is used in png terminal, the "truecolor" option must be selected.

The png file is shown below and the pdf file can be downloaded here.

Saturday, September 17, 2011

Plot histograms using boxes

Some one may ask:"There is histogram plot style in gnuplot, why plot it with boxes?" I would like to say there is some restriction on the built in histogram plot style, for example the x-axis is always using the row number, you can not make it using the coloumns in the data file.

The simplest case is that there is only one group of data to be plotted. In this case you just set the boxwidth to a proper value, for example 0.95, and plot it with boxes. Here is an example.
The data file is like this:
1975    0.5     9.0
1980    2.0     12.0
1985    2.5     10.1
1990    2.6     9.1
1995    2.0     7.2
2000    5.0     8.0
2005    10.2    6.0
2010    15.1    6.2
The plotting script is like this:
reset
set term png truecolor
set output "profit.png"
set xlabel "Year"
set ylabel "Profit(Million Dollars)"
set grid
set boxwidth 0.95 relative
set style fill transparent solid 0.5 noborder
plot "profit.dat" u 1:2 w boxes lc rgb"green" notitle
This example plot a graph like this one:

Plot histogram using boxes with one group of data

When there is more than one group of data to plot, the boxwidth and gap between the boxes should be calculated carefully. We do it like this:
reset
dx=5.
n=2
total_box_width_relative=0.75
gap_width_relative=0.1
d_width=(gap_width_relative+total_box_width_relative)*dx/2.
reset
set term png truecolor
set output "profit.png"
set xlabel "Year"
set ylabel "Profit(Million Dollars)"
set grid
set boxwidth total_box_width_relative/n relative
set style fill transparent solid 0.5 noborder
plot "profit.dat" u 1:2 w boxes lc rgb"green" notitle,\
     "profit.dat" u ($1+d_width):3 w boxes lc rgb"red" notitle
This time we get a histogram with two group of data like this:

Plot histogram using boxes with more than one group of data
Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.