2

I know this was asked before a while ago using images for points but I was wondering whether someone can provide more detailed help, or whether any recent changes in gnuplot make this easier?

My question is slightly different and I didn't want to reopen a 6yo question

I'm trying to produce a plot for a weather forecast similar to this: AIX weather widget screenshot

I have some data from openweathermap's api, and an icon set - plotting the temp, rainfall, etc is trivial.. What I would like to do is plot an image/ icon to show the weather just above the temperature plot

It looks like center would work, but how can I get center to correspond to a datapoint - or more accurately to a few pixels above the datapoint

Any alternative suggestions would also be gratefully received

2
  • Could you please post what you've tried so far? Commented Apr 28, 2016 at 6:13
  • I've not really made any progress on this yet as I'm not sure which direction to take. As mentioned above I think center could work if I can place it correctly. I was hoping that there would be a function to use an image as a column/ box Another option could be to use rgbimage and try to manually place the images according to the data point coordinates.. This is basically why I'm asking for help as I'm not sure which option is the best way to proceed Commented Apr 28, 2016 at 8:28

1 Answer 1

1

Here's how to do it in two steps:

IMG_LIST="cloud.png sun.png"
X=""
Y=""
IMG=""
storedata(x,y,index_img)=                               \
        (X=X.sprintf(" %f",x),                          \
        Y=Y.sprintf(" %f",y),                           \
        IMG=IMG." ".word(IMG_LIST,int(index_img)),y)

plot '-' using 1:(storedata($1,$2,$3))
0.5 23 2
1.5 27 2
2.5 19 1
e

plot [0:3][0:40] for [i=1:words(IMG)] word(IMG,i) binary filetype=png center=(word(X,i),word(Y,i)) dx=0.005 dy=0.05 with rgbimage notitle

First step is to build lists (space separated elements in strings X, Y, and IMG) with the plot data. Then a for-loop plots the images at the desired location. The dx and dy need to be adjusted depending on your image size and the plot ranges (could be automated with GPVAL_* data).

enter image description here

Sign up to request clarification or add additional context in comments.

9 Comments

Thanks VERY much for the help - that's exactly what I'm trying to achieve. I understand (most of) what this is doing.. But.. Using your script as is only generates a plot with 'pluses' at the points for me.. I have moved 'sun' and 'cloud' icons to the same directory. They are 128x128 pixels. I have set 'terminal png' and specified a path for the png. And I have a couple of questions (probably very basic I'm afraid - apols in advance). How do I point 'storedata' to my data file (called results.csv)? How do I point the list of images to a specific directory? thanks!
Just realised it's gnuplot interactive - which I'm not familiar with. I'm trying to script this (on Ubuntu) and cannot get it working as a script. Also, how can I point 'storedata' to my data file which looks something like this: ` - main/temp weather/0/icon dt_txt - 8.65 03d 2016-04-29 09:00:00 - 9.31 04d 2016-04-29 12:00:00 - 9.27 04d 2016-04-29 15:00:00`
This can be used as a script, just save it in a file and run gnuplot -persist on it, or add a terminal and output option before the last plot command to save to a file. To change the data source, replace the '-' in the first plot command, and modify the using to take into account your specific format. You can ask another question if you have difficulty with this.
You can replace the file names in the IMG_LIST variable with names including the full path (or relative path). If there are spaces in the pathname, you'll probably need to escape them (write `` before the space character)
Thanks again for your help @Joce - I'm very grateful! I'm very nearly there - it's plotting the 'centers', but not the images. My data file contains values that correspond to the icon names: the data file contains for example 03d, 04d, 04d, 10d, 04n, 03n in col 13, and I have image files that correspond - 03d.png, 04d.png, 04d.png, 10d.png, etc.. So I think I could just perform a 'look-up' rather than an index.. But would need some help with that please! Thanks in advance
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.