Save saves the plot to an image file. The file format is determined by the extension. Supported extensions are: - .eps - .jpg|.jpeg - .pdf - .png - .svg - .tex - .tif|.tiff
(w, h vg.Length, file string)
| 523 | // - .tex |
| 524 | // - .tif|.tiff |
| 525 | func (p *Plot) Save(w, h vg.Length, file string) (err error) { |
| 526 | f, err := os.Create(file) |
| 527 | if err != nil { |
| 528 | return err |
| 529 | } |
| 530 | defer func() { |
| 531 | e := f.Close() |
| 532 | if err == nil { |
| 533 | err = e |
| 534 | } |
| 535 | }() |
| 536 | |
| 537 | format := strings.ToLower(filepath.Ext(file)) |
| 538 | if len(format) != 0 { |
| 539 | format = format[1:] |
| 540 | } |
| 541 | c, err := p.WriterTo(w, h, format) |
| 542 | if err != nil { |
| 543 | return err |
| 544 | } |
| 545 | |
| 546 | _, err = c.WriteTo(f) |
| 547 | return err |
| 548 | } |
| 549 | |
| 550 | func init() { |
| 551 | font.DefaultCache.Add(liberation.Collection()) |