Example #1
0
// Draw draws or save figure with plot
//  dirout -- directory to save figure
//  fname  -- file name; e.g. myplot.eps or myplot.png. Use "" to skip saving
//  show   -- shows figure
//  extra  -- is called just after Subplot command and before any plotting
//  Note: subplots will be split if using 'eps' files
func Draw(dirout, fname string, show bool, extra ExtraPlt) {
	var fnk string // filename key
	var ext string // extension
	var eps bool   // is eps figure
	if fname != "" {
		fnk = io.FnKey(fname)
		ext = io.FnExt(fname)
		eps = ext == ".eps"
	}
	nplots := len(Splots)
	nr, nc := utl.BestSquare(nplots)
	var k int
	for i := 0; i < nr; i++ {
		for j := 0; j < nc; j++ {
			if !eps {
				plt.Subplot(nr, nc, k+1)
			}
			if extra != nil {
				extra(i+1, j+1, nplots)
			}
			if Splots[k].Title != "" {
				plt.Title(Splots[k].Title, Splots[k].Topts)
			}
			data := Splots[k].Data
			for _, d := range data {
				if d.Style.L == "" {
					d.Style.L = d.Alias
				}
				x, y := d.X, d.Y
				if math.Abs(Splots[k].Xscale) > 0 {
					x = make([]float64, len(d.X))
					la.VecCopy(x, Splots[k].Xscale, d.X)
				}
				if math.Abs(Splots[k].Yscale) > 0 {
					y = make([]float64, len(d.Y))
					la.VecCopy(y, Splots[k].Yscale, d.Y)
				}
				plt.Plot(x, y, d.Style.GetArgs("clip_on=0"))
			}
			plt.Gll(Splots[k].Xlbl, Splots[k].Ylbl, Splots[k].GllArgs)
			if eps {
				savefig(dirout, fnk, ext, k)
				plt.Clf()
			}
			k += 1
		}
	}
	if !eps && fname != "" {
		savefig(dirout, fnk, ext, -1)
	}
	if show {
		plt.Show()
	}
}
Example #2
0
// Plot runs the plot generation (basic set)
func (o *Plotter) Plot(keys []string, res []*State, sts [][]float64, first, last bool) {

	// auxiliary variables
	nr := imax(len(res), len(sts))
	if nr < 1 {
		return
	}
	x := make([]float64, nr)
	y := make([]float64, nr)
	o.P = make([]float64, nr)
	o.Q = make([]float64, nr)
	o.W = make([]float64, nr)
	o.Ev = make([]float64, nr)
	o.Ed = make([]float64, nr)

	// compute invariants
	for i := 0; i < len(res); i++ {
		if len(res[i].Sig) < 4 {
			chk.Panic("number of stress components is incorrect: %d", len(res[i].Sig))
		}
		o.P[i], o.Q[i], o.W[i] = tsr.M_pqw(res[i].Sig)
	}
	nsig := len(res[0].Sig)
	devε := make([]float64, nsig)
	for i := 0; i < len(sts); i++ {
		if len(sts[i]) < 4 {
			chk.Panic("number of strain components is incorrect: %d", len(sts[i]))
		}
		_, o.Ev[i], o.Ed[i] = tsr.M_devε(devε, sts[i])
	}

	// clear previous figure
	if first {
		plt.Clf()
		plt.SplotGap(0.35, 0.35)
		if o.Hspace > 0 {
			plt.SetHspace(o.Hspace)
		}
		if o.Vspace > 0 {
			plt.SetVspace(o.Vspace)
		}
	}

	// number of points for contour
	if o.NptsPq < 2 {
		o.NptsPq = 61
	}
	if o.NptsOct < 2 {
		o.NptsOct = 41
	}
	if o.NptsSig < 2 {
		o.NptsSig = 41
	}

	// subplot variables
	o.Pidx = 1
	o.Ncol, o.Nrow = utl.BestSquare(len(keys))
	if len(keys) == 2 {
		o.Ncol, o.Nrow = 1, 2
	}
	if len(keys) == 3 {
		o.Ncol, o.Nrow = 1, 3
	}

	// do plot
	for _, key := range keys {
		o.Subplot()
		switch key {
		case "ed,q":
			o.QdivP = false
			o.Plot_ed_q(x, y, res, sts, last)
		case "ed,q/p":
			o.QdivP = true
			o.Plot_ed_q(x, y, res, sts, last)
		case "p,q":
			o.WithYs = false
			o.Plot_p_q(x, y, res, sts, last)
		case "p,q,ys":
			o.WithYs = true
			o.Plot_p_q(x, y, res, sts, last)
		case "ed,ev":
			o.Plot_ed_ev(x, y, res, sts, last)
		case "p,ev":
			o.LogP = false
			o.Plot_p_ev(x, y, res, sts, last)
		case "log(p),ev":
			o.LogP = true
			o.Plot_p_ev(x, y, res, sts, last)
		case "i,f":
			o.Plot_i_f(x, y, res, sts, last)
		case "i,alp":
			o.Plot_i_alp(x, y, res, sts, last)
		case "Dgam,f":
			o.Plot_Dgam_f(x, y, res, sts, last)
		case "oct":
			o.WithYs = false
			o.Plot_oct(x, y, res, sts, last)
		case "oct,ys":
			o.WithYs = true
			o.Plot_oct(x, y, res, sts, last)
		case "s3,s1":
			o.WithYs = false
			o.Plot_s3_s1(x, y, res, sts, last)
		case "s3,s1,ys":
			o.WithYs = true
			o.Plot_s3_s1(x, y, res, sts, last)
		case "empty":
			continue
		default:
			chk.Panic("cannot handle key=%q", key)
		}
		if o.Split && last {
			o.Save("_", key)
		}
	}

	// save figure
	if !o.Split && last {
		o.Save("", "")
	}
}