at.plot.response#
Plot Observable value as a function of
Variable.
Functions
|
Plot obs values as a function of var. |
- plot_response(var, obs, rng, ax=None, xlabel='', ylabel='', title='', color_offset=0, **kwargs)[source]#
Plot obs values as a function of var.
- Parameters:
var (VariableBase) – Variable object.
obs (ObservableList) – list of Observables.
rng (Iterable[float]) – range of variation for the variable.
ax (Axes | None) –
Axesobject. IfNone, a new figure will be created.xlabel (str) – x-axis label. If empty, the variable name will be used.
ylabel (str) – y-axis label.
title (str) – plot title.
color_offset (int) – offset in the matplotlib line color cycle.
**kwargs – Additional keyword arguments are transmitted to the
Axescreation function.
- Returns:
ax – the
Axesobject.
Example
Minimal example using only default values:
>>> obs = at.ObservableList( ... [ ... at.EmittanceObservable("emittances", plane="x"), ... at.EmittanceObservable("emittances", plane="y"), ... ], ... ring=ring, ... ) >>> var = at.AttributeVariable(ring, "energy", name="energy [eV]") >>> plot_response(var, obs, np.arange(3.0e9, 6.01e9, 0.5e9)) >>>
Example showing the formatting possibilities by:
using the
Observable.plot_fmtattribute for line formatting,using the
Observable.nameattribute for curve labels,using dual y-axis by calling
plot_response()twice,avoiding duplicate line colors with the color_offset parameter,
using the ylabel and title parameters.
>>> obsleft =at.ObservableList( ... [ ... at.LocalOpticsObservable( ... [0], "beta", plane="x", ... name=r"$\beta_x$", ... plot_fmt={"linewidth": 3.0, "marker": "o"} ... ), ... at.LocalOpticsObservable( ... [0], "beta", plane="y", name=r"$\beta_z$", plot_fmt="--" ... ) ... ], ... ring=ring ... ) >>> >>> obsright =at.ObservableList( ... [ ... at.GlobalOpticsObservable("tune", plane="x", name=r"$\nu_x$"), ... at.GlobalOpticsObservable("tune", plane="y", name=r"$\nu_x$"), ... ], ... ring=ring ... ) >>> # On the left y-axis >>> ax = at.plot_response( ... var, ... obsleft, ... np.arange(2.4, 2.7, 0.02), ... ylabel="beta [m]", ... title="Example of plot_response" ... ) >>> # On the right y-axis >>> ax2 = at.plot_response( ... var, ... obsright, ... np.arange(2.4, 2.7, 0.02), ... ylabel="tune", ... ax=ax.twinx(), ... color_offset=2 ... ) >>> ax.set_ylim(0.0, 10.0) >>> ax2.set_ylim(0.0, 1.2) >>> ax2.grid(False)
Example varying an evaluation parameter:
>>> obs =at.ObservableList( ... [ ... at.LocalOpticsObservable([0], "beta", plane="x", name=r"$\beta_x$"), ... at.LocalOpticsObservable([0], "beta", plane="y", name=r"$\beta_z$") ... ], ... ring=ring, ... dp = 0.0 ... ) >>> var = at.EvaluationVariable(obs, "dp", name=r"$\delta$") >>> ax=at.plot_response( ... var, obs, np.arange(-0.03, 0.0301,0.001), ylabel=r"$\beta\;[m]$" ... )