Friday, September 2, 2011

Gnuplot background image

Gnuplot can read png binary file and then plot it on the canvas. Using this utility we can add a background image to our plot. Let us see an example script.
reset
set term png
set output "world_population.png"
set multiplot
set xrange [0:799] 
set yrange [0:409]
#As the background picture's size is 800x410,
#we choose xrange and yrange of these values
unset tics
unset border
set lmargin at screen 0.175
set rmargin at screen 0.9
set bmargin at screen 0.15
set tmargin at screen 0.9
#Plot the background image
plot "map.png" binary filetype=png w rgbimage
#The x and y range of the population data file
set xrange [1740:2020]
set yrange [0:7000]
set border
set tics out nomirror scale 2
set mxtics 5
set key left
set xlabel "Year"
set ylabel "Population(in millions)"
plot "population.dat" u 1:2 w lp lw 2 ps 1 pt 7 title "world",\
     "population.dat" u 1:3 w lp lw 2 ps 1 pt 7 title "Africa",\
     "population.dat" u 1:4 w lp lw 2 ps 1 pt 7 title "Asia",\
     "population.dat" u 1:5 w lp lw 2 ps 1 pt 7 title "Europe",\
     "population.dat" u 1:6 w lp lw 2 ps 1 pt 7 title "Katub America",\
     "population.dat" u 1:7 w lp lw 2 ps 1 pt 7 title "Northern America",\
     "population.dat" u 1:8 w lp lw 2 ps 1 pt 7 title "Oceania"
unset multiplot
In this script, map.png is our background image with size 800x410 (That is why we choose xrange and yrange to be 0-799 and 0-409 respectively). population.dat is a file containing information of world population from 0 AD to 2000 AD. The first plot command is used to plot the background image, while the second plot command is used to plot our world population data file. To make these two plot coincide with each other, l,r,t,bmargin are set in the screen coordinate. The data file is as follows:
#Data from http://en.wikipedia.org/wiki/World_population
#Year  World  Africa  Asia  Europe  Latin America  Northern America  Oceania
1750  791  106  502  163  16  2  2  
1800  978  107  635  203  24  7  2  
1850  1262  111  809  276  38  26  2  
1900  1650  133  947  408  74  82  6  
1950  2519  221  1398  547  167  172  12.8  
1955  2756  247  1542  575  191  187  14.3  
1960  2982  277  1674  601  209  204  15.9  
1965  3335  314  1899  634  250  219  17.6  
1970  3692  357  2143  656  285  232  19.4  
1975  4068  408  2397  675  322  243  21.5  
1980  4435  470  2632  692  361  256  22.8  
1985  4831  542  2887  706  401  269  24.7  
1990  5263  622  3168  721  441  283  26.7  
1995  5674  707  3430  727  481  299  28.9  
2000  6070  796  3680  728  520  316  31.0  
2005  6454  888  3917  725  558  332  32.9  
2008  6707  973  4054  732  577  337  34.3
To use background image file of format other than png, we shold first convert it to a png file. This task can be done well using ImageMagick.

At last, this is the picture file world_population.png produced by the plotting script.

Gnuplot background image

28 comments:

  1. I get a failure when I try your idea:

    set term png
    "population.plt", line 2: You can't change the terminal in multiplot mode

    ReplyDelete
  2. Every time you using command "set multiplot", remember after the multiplot you should "unset multiplot".

    ReplyDelete
  3. Which version do you need to run this script?

    ReplyDelete
    Replies
    1. This script can be run under gnuplot 4.6 or 4.4.4 . And since this script is very simple, I think it can also be run under some lower version.

      Delete
  4. You would not guess how hard it is to find informastion on including watermarks in gnuplot. Most people seem to do this with external tools, and I even failed to locate it in the official documentation (used the wrong keywords for my searches obviously). Thanks for the explanation, that came very handy.

    ReplyDelete
  5. I would like to apply Arnold's cat map to an image.
    (sse pg 5 of http://www.maths.bristol.ac.uk/~maxcu/CATmap.pdf )

    is it feasible with gnuplot?

    ReplyDelete
    Replies
    1. It seems this is not a gnuplot feasible task. You konw gnuplot is a plotting a tool, not a data processing software.

      Delete
  6. IOT Training in Bangalore - Live Online & Classroom
    Iot Training course observes iot as the platform for networking of different devices on the internet and their inter related communication. Iot Training in Bangalore

    ReplyDelete
  7. Gaining Python certifications will validate your skills and advance your career.
    python certification

    ReplyDelete
  8. It is very good and very informative. There is a useful information in it.Thanks for posting... IoT Training In Hyderabad

    ReplyDelete
  9. Wow it is really wonderful and awesome thus it is veWow, it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot.

    selenium training in chennai

    selenium training in chennai

    selenium online training in chennai

    selenium training in bangalore

    selenium training in hyderabad

    selenium training in coimbatore

    selenium online training

    ReplyDelete

  10. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.

    Azure Training in Chennai

    Azure Training in Bangalore

    Azure Training in Hyderabad

    Azure Training in Pune

    Azure Training | microsoft azure certification | Azure Online Training Course

    Azure Online Training

    ReplyDelete
  11. Thanks for sharing this wonderful content.its very useful to us.This is incredible,I feel really happy to have seen your webpage I gained many unknown information, the way you have clearly explained is really fantastic.keep posting such useful information.
    DevOps Training in Chennai

    DevOps Online Training in Chennai

    DevOps Training in Bangalore

    DevOps Training in Hyderabad

    DevOps Training in Coimbatore

    DevOps Training

    DevOps Online Training

    ReplyDelete
  12. Great site and a great topic as well I really get amazed to read this.This is incredible,I feel really happy to have seen your webpage.I gained many unknown information, the way you have clearly explained is really fantastic.keep posting such useful information.
    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training

    ReplyDelete
  13. I feel really happy to have seen your webpage.I am feeling grateful to read this.you gave a nice information for us.please updating more stuff content...keep up!!

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training

    ReplyDelete
  14. Excellent Blog! I would Thanks for sharing this wonderful content.its very useful to us.I gained many unknown information, the way you have clearly explained is really fantastic.keep posting such useful information.
    IELTS Coaching in chennai

    German Classes in Chennai

    GRE Coaching Classes in Chennai

    TOEFL Coaching in Chennai

    spoken english classes in chennai | Communication training


    ReplyDelete
  15. I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!



    AWS Course in Bangalore

    AWS Course in Hyderabad

    AWS Course in Coimbatore

    AWS Course

    AWS Certification Course

    AWS Certification Training

    AWS Online Training

    AWS Training

    ReplyDelete
  16. I am jovial you take pride in what you write. It makes you stand way out from many other writers that can not push high-quality content like you. photographe publicitaire

    ReplyDelete

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.