How to save Plotchart canvas other than PostScript without displaying it?

有些话、适合烂在心里 提交于 2019-12-12 03:43:42

问题


I read the section OTHER OUTPUT FORMATS of Plotchart documentation, but still can't figure out how to do it.

I want to:

  1. Save canvas as image without displaying it. So I can run it in batch mode.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!