Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnuplot - How can I save a graphics file of a plot that is the same as I designed it in xterminal?

I have been making plots for some time now, and they are precisely the way I like them, on screen. The data is coming in from sensors related to solar power collection and storage.

Plotted on screen they look great so I do a screen region capture to save them.

So now I would like to automate the saving process.

Here is what I have done so far:

  • I set up a cron job so they would be run right at midnight, capturing the whole day and saving it as a .png file
  • Then it moves the "today.dat" data file to the archive named by date.
  • This part is all working as designed.

EXCEPT, by using .PNG the images do not look the same. I really thought png would be the best option, but it turns out that the font used for the X-axis (HH:MM ticks) is too thick and they run together. It looks like a crayon-drawn version of my plot designs.

Can someone please give me some guidance on how to best programatically generate the plots for saving so they look like the way I designed them?

like image 841
SDsolar Avatar asked Nov 30 '25 01:11

SDsolar


1 Answers

As pointed out in the comments above, the best way is probably to use a different terminal for output to an image file, and simply ignore the fact that the generated images are not identical to what you see on your screen when using the x11 terminal. However, if you really need an exact copy, there are (at least) two options:

  1. You could automate the process of taking a screenshot. You can even do this from within gnuplot, where it might come handy that the GPVAL_TERM_WINDOWID variable contains the X Windows ID for the current plot window. You can use that to make a screenshot of the window after you made the plot:

    system(sprintf("xwd -id 0x%x | convert xwd:- screenshot.png", GPVAL_TERM_WINDOWID))
    

    Here I included a call to convert to convert the xwd file format to png.

  2. Another option is to use the xlib terminal, which saves the sequence of commands that the gnuplot_x11 helper application turns into the window you see on the screen. For example,

    set term push; set term xlib; set output "file.xlib"; replot; set output; set term pop
    

    will create the file file.xlib that has all the information of the last plot. To later view this plot, use

    gnuplot_x11 -noevents -persist < file.xlib
    

    where you might have to specify the path to gnuplot_x11.

like image 129
user8153 Avatar answered Dec 01 '25 21:12

user8153