问题
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?
回答1:
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:
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.Another option is to use the
xlib
terminal, which saves the sequence of commands that thegnuplot_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, usegnuplot_x11 -noevents -persist < file.xlib
where you might have to specify the path to
gnuplot_x11
.
回答2:
Similar as @user8153 suggested for x11
, you can use import, which is as convert
an imagemagick tool
system("import -window ".GPVAL_TERM_WINDOWID." screenshot.png")
Convenient is also a shortcut to copy the image into clipboard and paste it with Ctrl+v elsewhere:
bind Ctrl-c 'system("import -window ".GPVAL_TERM_WINDOWID." png:- | xclip -sel clip -t image/png")'
See also Show graph on display and save it to file simultaneously in gnuplot.
来源:https://stackoverflow.com/questions/44468524/gnuplot-how-can-i-save-a-graphics-file-of-a-plot-that-is-the-same-as-i-designe