pablo
pablo

Reputation: 385

Compose a plot with an image and a plot of a datafile matrix with transparency

I am trying to make a plot using a city map image

(map of Ghent)

and overlay this one

enter image description here

which match the streets of this location, and produce a figure like this

enter image description here

produced via GIMP.

I would like to make a plot similar to the one above with Gnuplot, overlaying the two images with the map at the back and the pher.txt data at front.

I can use this script to plot the map:

set encoding iso_8859_1
set term postscript eps enhanced color size 5in,5in
set output 'image.eps'
unset key; unset tics; unset border
set size ratio -1
set size square
set lmargin screen 0
set bmargin screen 0
set rmargin screen 1
set tmargin screen 1
plot 'ghent0.png' binary filetype=png with rgbimage

borrowed from this link of Gnuplotting to plot the map.

To plot the heatmap I use this code:

set terminal pngcairo nobackground #size 800,800
# set encoding iso_8859_1
# set term postscript eps enhanced color size 5in,5in
set output 'foo.png'
set size square
unset xtics 
unset ytics
val = 0
set autoscale xfix
set autoscale yfix
set cbrange [0:9]
set yrange [:] reverse
# plot 'pher.txt' matrix using ($1 == val ? NaN : $1) with image notitle
plot 'pher.txt' matrix with image notitle

To make the black color transparent I have tried plot 'pher.txt' matrix using ($1 == val ? NaN : $1) with image notitle borrowed from "Transparency for specific values in matrix ..." which it supose to tell Gnuplot to put NaN values where there are 0's in the pher.txt matrix datafile. However, it does not work. Besides, the two layers (image map and heatmap with black transparent) should be resized so heatmap lines match the streets of the map.

Note: the map image and the file pher.txt are in this link MapDatafile

Regards

Upvotes: 2

Views: 632

Answers (1)

user8153
user8153

Reputation: 4095

When you plot ... matrix with image the image values are in the third column, not in the first. Here is a solution that plots that map in (x,y) coordinate system and your data in the (x2,y2) coordinate system. This way you rescale the latter relative to the former simply by setting x2range and y2range:

set size square
set xtics nomirror
set ytics nomirror
set x2tic
set y2tic
set x2range [-1:200]
set y2range [-1:204] reverse
set autoscale noextend
set cbrange [0:9]
plot 'ghent0.jpg' binary filetype=jpg with rgbimage, \
     'pher.txt' matrix using 1:2:($3 == 0 ? NaN : $3) axes x2y2 with image notitle

enter image description here

Upvotes: 2

Related Questions