问题
I read the section OTHER OUTPUT FORMATS of Plotchart documentation, but still can't figure out how to do it.
I want to:
- Save canvas as image without displaying it. So I can run it in batch mode.
- Save in other format. (ex: jpeg, png...)
A brief example is appreciated.
回答1:
I didn't try this solution, but the man page you linked describes a saveplot
command to store the plot into a Postscript (or other image format) file.
Once you created your plot widget, you can do something like
.plot saveplot filename.ps -plotregion bbox
where the -plotregion bbox
says to save all the plot and not just the visible part (-plotregion window
, which is the default).
回答2:
I found Img library is capable to converts Postscript into various formats, and a quick and dirty way do not display the canvas is to run exit
immediately.
Here is an example:
package require Plotchart
package require Img
canvas .c -background white -width 400 -height 200
pack .c -fill both
set s [::Plotchart::createXYPlot .c {0.0 100.0 10.0} {0.0 100.0 20.0}]
foreach {x y} {0.0 32.0 10.0 50.0 25.0 60.0 78.0 11.0 } {
$s plot series1 $x $y
}
$s title "Data series"
set file "test.ps"
$s saveplot $file
set root [file rootname $file]
set image [image create photo -file $file]
foreach {f suffix} {JPEG jpg GIF gif PNG png} {
$image write $root.$suffix -format $f
}
exit
来源:https://stackoverflow.com/questions/15330242/how-to-save-plotchart-canvas-other-than-postscript-without-displaying-it