Plotting¶
Classes related to plotting.
API¶
Classes:
Plotter([config, dpi])Class to hold plotting routines
Exceptions:
- class plotter.Plotter(config=None, dpi=100)¶
Class to hold plotting routines
Class containing methods for plotting results. Each plotting method saves a plot in the outplot/plots directory, and returns a matplotlib figure object.
- Parameters:
- configa
dyn.config_reader.Configurationobject- dpifloat, optional
The resolution of saved figures (if not overridden later). The default is 100 dpi.
Methods:
beta_plot([which_chi2, Rmax_arcs, figtype, ...])Generates anisotropy plot
make_chi2_plot([which_chi2, n_excl, figtype])Generates a chisquare plot
make_chi2_vs_model_id_plot([which_chi2, figtype])Generates a chi2 vs.
mass_plot([which_chi2, Rmax_arcs, x_scale, ...])Generates cumulative mass plot
orbit_distribution([model, minr, maxr, ...])Make the orbit distibution plot
orbit_plot([model, Rmax_arcs, ocut, figtype])Generates an orbit plot for the selected model
plot_kinematic_maps([model, kin_set, ...])Generates a kinematic map of a model with v, sigma, h3, h4...
qpu_plot([which_chi2, Rmax_arcs, x_scale, ...])Generates triaxiality plot
rmax_zmax_plot([model, max_r, max_z, ...])Generate a Rmax-zmax plot for a given model
shiftedColorMap(cmap[, start, midpoint, ...])Function to offset the "center" of a colormap.
- beta_plot(which_chi2=None, Rmax_arcs=None, figtype=None, r_scale='linear')¶
Generates anisotropy plot
The plot shows the intrinsic anisotropy beta_r as a function of the distance from the galaxy or cluster centre (in arcsec). beta_r is computed from the verlocity dispersion sigma in spherical coordinates (r, phi, theta), using the tangential velocity dispersion (sigma_t^2=(sigma_phi^2+sigma_theta^2)*0.5) and radial velocity dispersion (sigma_r). The velocity dispersion components are computed from the first and second moments via sigma_ij = ⟨v_j v_k⟩ - ⟨v_j⟩⟨v_k⟩
beta_r = 1 - (sigma_t/sigma_r)^2
Solid lines and shaded areas represent the mean and standard deviation of the anisotropy of models having parameters in a confidence region around the minimum chisquare.
- Parameters:
- which_chi2STR, optional
Which chi2 is used for determining the best models. If None, the setting from the configuration file will be used. The default is None.
- Rmax_arcsnumerical value
Determines the upper range of the x-axis.
- figtypeSTR, optional
Determines the file extension to use when saving the figure. If None, the default setting is used (‘.png’).
- r_scalestr, optional
switches between logarithmic (r_scale=’log’) and linear (r_scale=’linear’) scaling of the x-axis. Defaults to ‘linear’.
- Raises
- ——
- ValueError
If which_chi2 is neither None nor a valid chi2 type.
- ValueError
If Rmax_arcs is not set to a numerical value.
- Returns:
- fig1matplotlib.pyplot.figure
Figure instance.
- fig2matplotlib.pyplot.figure
Figure instance.
- make_chi2_plot(which_chi2=None, n_excl=0, figtype=None)¶
Generates a chisquare plot
The models generated are shown on a grid of parameter space. The best-fit model is marked with a black cross. The coloured circles represent models within 3 sigma confidence level (light colours and larger circles indicate smaller values of the chisquare). The small black dots indicate the models outside this confidence region.
- Parameters:
- which_chi2STR, optional
Which chi2 is used for determining the best models. If None, the setting from the configuration file will be used. The default is None.
- n_exclinteger, optional
Determines how many models (in the initial burn-in phase of the fit) to exclude from the plot. Must be an integer number. Default is 0 (all models are shown). Use this with caution!
- figtypeSTR, optional
Determines the file extension to use when saving the figure. If None, the default setting is used (‘.png’).
- Returns:
- figmatplotlib.pyplot.figure
Figure instance.
- Raises:
- ValueError
If which_chi2 is neither None nor a valid chi2 type.
- make_chi2_vs_model_id_plot(which_chi2=None, figtype=None)¶
Generates a chi2 vs. model id plot
- Parameters:
- which_chi2STR, optional
Which chi2 is used for determining the best models. If None, the setting from the configuration file will be used. The default is None.
- figtypeSTR, optional
Determines the file extension to use when saving the figure. If None, the default setting is used (‘.png’).
- Returns:
- figmatplotlib.pyplot.figure
Figure instance.
- Raises:
- ValueError
If which_chi2 is neither None nor a valid chi2 type.
- mass_plot(which_chi2=None, Rmax_arcs=None, x_scale='linear', y_scale='linear', figtype=None)¶
Generates cumulative mass plot
The enclosed mass profiles are shown for the mass-follows-light component (red), for the dark matter (blue), and for the sum of the two (black). The solid lines correspond to the best-fit model, the shaded areas represent 1 sigma uncertainties. The mass (in solar units) is plotted here as a function of the distancefrom the galactic centre, both in arcsec (bottom axis) and in pc (top axis).
- Parameters:
- which_chi2STR, optional
Which chi2 is used for determining the best models. If None, the setting from the configuration file will be used. The default is None.
- Rmax_arcsnumerical value, optional
Determines the upper range [arcsec] of the x-axis. If None, it is set to the config file’s
orblib_settings: logrmaxvalue. The default value is None.- x_scalestr, optional
switches between logarithmic (x_scale=’log’) and linear (x_scale=’linear’) scaling of the x axis. The default is ‘linear’.
- y_scalestr, optional
switches between logarithmic (y_scale=’log’) and linear (y_scale=’linear’) scaling of the y axis. The default is ‘linear’.
- figtypeSTR, optional
Determines the file extension to use when saving the figure. If None, the default setting is used (‘.png’).
- Returns:
- figmatplotlib.pyplot.figure
Figure instance.
- Raises:
- ValueError
If which_chi2 is neither None nor a valid chi2 type.
- orbit_distribution(model=None, minr=None, maxr=None, r_scale='log', nr=50, nl=61, equal_weighted_orbits=False, orientation='horizontal', figtype='.png', subset='all', dL=1e+17, force_lambda_z=False, getdata=False)¶
Make the orbit distibution plot
Plots a model’s orbit distribution in (radius, circularity) space. Orbits are split by type: [long, short, intermediate]-axis tubes and box orbits (classification is handled by
orblib.classify_orbits). Each orbit only contributes to the appropriate distribution, e.g. box orbits only appear in the box-orbit panel. Compared to older versions of orbit distibution plots, this means that there is now no “stripe” atlmd_z=0, since any non short-axis tubes have been moved to their own panel. The fraction of orbits in each type is added as title. Note that individual orbits now contribute a point to the distibution, rather than a single point per orbit-bundle. This means that - ifdithering>1- the orbit distributions are sampled better compared to previous versions.
- Parameters:
- modeloptional, a dynamite.model.Model object
Determines which model is used for the plot. If
None, the minimum chi^2 model is used (the setting in the configuration file’s parameter settings is used to determine which chi^2 is used).- minrfloat, optional
the minimum radius [kpc] to show in the plot. If
None, this is set to the minimum radius of the orbit library- maxrfloat, optional
the maximum radius [kpc] to show in the plot. If
None, this is set to the minimum radius of the orbit library- r_scalestr, optional
switches between logarithmic (r_scale=’log’) and linear (r_scale=’linear’) scaling and binning of the (minr,maxr) r interval. The default is ‘log’.
- nrint, optional
number of radial bins, by default 50
- nlint, optional
number of circularity bins, by default 61
- equal_weighted_orbitsbool, optional
weight all orbit bundels equally, instead of using the model’s best-fitting weights. Useful to see the distributiuon of the full orbit libary, by default
False- orientationstr, optional
arrange panels
'horizontal'or'vertical', by default'horizontal'- figtypestr, optional
file type extension to save the plot, by default
'.png'- subsetstr, optional
either
'all'or any combination of['long', 'short', 'intermediate', 'box']separated by'+'e.g.'long+box','box+short+intermediate'. Any order works, but the order does not affect the order of plots. By default'all'- dLfloat, default 1e17
Threshold angular momentum used for orbit classification
- force_lambda_zbool, dafault False
if true, then we force the orbit distribution to only be collapsed onto (r, lambda_z) space. This is done by forcing all orbits to be classified as short axis-tube orbits.
- getdatabool, optional
whether to return the orbit distribtuion data plotted in the plot, by default
False- Returns:
- mpl.Figure or a tuple (mpl.Figure, np.array) if
getdata=Truethe figure object, and (if
getdata=True) a 3D array where the 1st dimension indexes over 4 orbit types (long, int., short, box), 2nd over radii, 3rd over circularities.- Raises:
- NotImplementedError
if
orientationis invalid- ValueError
if orbit classes don’t match the projection tensor or orbit class names are invalid
- orbit_plot(model=None, Rmax_arcs=None, ocut=(0.8, 0.25, -0.25, -0.8), figtype=None)¶
Generates an orbit plot for the selected model
This plot shows the stellar orbit distribution, described as probability density of orbits; circularity (lambda_z) is represented here as a function of the distance from the galactic centre r (in arcsec).
- Parameters:
- modelmodel, optional
Determines which model is used for the plot. If model = None, the model corresponding to the minimum chisquare (so far) is used; the setting in the configuration file’s parameter settings is used to determine which chisquare to consider. The default is None.
- Rmax_arcsnumerical value
upper radial limit for orbit selection, in arcsec i.e only orbits extending up to Rmax_arcs are plotted
- ocutiterable of numerical values, optional
The orbit cuts in lambda_z. The plot will include horizontal dashed lines at the lambda_z levels in ocut. Per default, ocut will have four levels (0.8, 0.25, -0.25, -0.8), interpreted as (lim_cold, lim_warm, lim_hot, lim_cr_warm), decomposing the plot into five regions: cold (lambda_z > lim_cold>), warm (lim_cold >= lambda_z > lim_warm), hot (lim_warm >= lambda_z > lim_hot), counter-rotating warm (lim_hot >= lambda_z > lim_cr_warm), and counter-rotating cold (lim_cr_warm >= lambda_z) orbits.
- figtypeSTR, optional
Determines the file extension to use when saving the figure. If None, the default setting is used (‘.png’).
- Returns:
- figmatplotlib.pyplot.figure
Figure instance.
- Raises:
- ValueError
If Rmax_arcs is not set to a numerical value.
- plot_kinematic_maps(model=None, kin_set=0, cbar_lims='default', figtype='.png', **kwargs)¶
Generates a kinematic map of a model with v, sigma, h3, h4…
Maps of the surface brightness, mean line-of-sight velocity, velocity dispersion, and higher order Gauss-Hermite moments are shown. The first row are data, the second row the best-fit model, and the third row the residuals.
- Parameters:
- modelmodel, optional
Determines which model is used for the plot. If model = None, the model corresponding to the minimum chisquare (so far) is used; the setting in the configuration file’s parameter settings is used to determine which chisquare to consider. The default is None.
- kin_setinteger or ‘all’
Determines which kinematic set to use for the plot. The value of this parameter should be the index of the data set (e.g. kin_set=0 , kin_set=1). The default is kin_set=0. If kin_set=’all’, several kinematic maps are produced, one for each kinematic dataset. A list of (fig,kin_set_name) is returned where fig are figure objects and kin_set_name are the names of the kinematics sets.
- cbar_limsstring or tuple/list
If set to ‘default’ (or not set), then ‘data’ is used for Gauss Hermite and [0,3] for BayesLOSVD kinematics.
Gauss Hermite kinematics only: determines which set of values defines the colorbar limits in the plots: ‘model’, ‘data’, ‘combined’, ‘default’, ‘user’. If ‘user’, then the parameters v_max and s_min_max must be defined.
BayesLOSVD kinematics only: if set to a tuple/list, cbar_lims defines the colorbar limits of the plotted reduced chi2 values.
- figtypeSTR, optional
Determines the file format of the saved figure, defaults to ‘.png’.
- v_sigma_optionSTR, optional
Gauss Hermite kinematics only: If ‘fit’, v_mean and v_sigma are calculated based on fitting Gaussians, if ‘moments’, v_mean and v_sigma are calculated directly from the model’s losvd histograms. The default is ‘fit’.
- v_maxfloat
Mandatory if cbar_lims==’user’ (Gauss Hermite kinematics). Defines the velocity colorbar limits. The limits are then [-v_max,v_max]. Not relevant for other values of cbar_lims nor for BayesLOSVD kinematics.
- s_min_maxtuple/list of floats
Mandatory if cbar_lims==’user’ and kinematics are of type Gauss Hermite and defines the velocity dispersion colorbar limits. The limits are then [s_min_max[0],s_min_max[1]]. Not relevant for other values of cbar_lims nor for BayesLOSVD kinematics.
- Returns:
- list or matplotlib.pyplot.figure
if kin_set == ‘all’, returns (matplotlib.pyplot.figure, string), i.e. Figure instances along with kinematics name or figure instance else, returns a matplotlib.pyplot.figure
- Raises:
- ValueError
If kin_set is not smaller than the number of kinematic sets.
- AssertionError
Gauss Hermite kinematics only: If cbar_lims is not one of ‘model’, ‘data’, ‘combined’, ‘default’, or ‘user’.
- ValueError
Gauss Hermite kinematics only: If cbar_lims==’user’ and v_max and/or s_min_max are not provided.
- ValueError
Gauss Hermite kinematics only: If v_sigma_option is not one of ‘moments’ or ‘fit’.
- ValueError
Gauss Hermite kinematics only: If the number of Gauss Hermite coefficients in the configuration file is inconsistent with the kinematic map data.
- qpu_plot(which_chi2=None, Rmax_arcs=None, x_scale='linear', y_scale='linear', figtype=None)¶
Generates triaxiality plot
The intrinsic flattenings q (C/A) and p (B/A) are shown here, with the blue and black lines respectively, as a function of the distance from the galactic centre (in arcsec). The value of T = (1-p^2)/(1-q^2) is also shown (red line).
- Parameters:
- which_chi2STR, optional
Which chi2 is used for determining the best models. If None, the setting from the configuration file will be used. The default is None.
- Rmax_arcsnumerical value, optional
Determines the upper range [arcsec] of the x-axis. If None, it is set to the config file’s
orblib_settings: logrmaxvalue. The default value is None.- x_scalestr, optional
switches between logarithmic (r_scale=’log’) and linear (r_scale=’linear’) scaling of the r axis. Defaults to ‘linear’.
- y_scalestr, optional
switches between logarithmic (r_scale=’log’) and linear (r_scale=’linear’) scaling of the mass axis. Defaults to ‘linear’.
- figtypeSTR, optional
Determines the file extension to use when saving the figure. If None, the default setting is used (‘.png’).
- Returns:
- figmatplotlib.pyplot.figure
Figure instance.
- Raises:
- ValueError
If which_chi2 is neither None nor a valid chi2 type.
- rmax_zmax_plot(model=None, max_r=None, max_z=None, col_scale='log', components='all', names='bulgedisk', figtype='.png')¶
Generate a Rmax-zmax plot for a given model
Generates a Rmax-zmax plot for a given model, showing the distribution of orbit weights in the Rmax-zmax plane. Optionally, the plot can be restricted to specific orbital components, based on a decomposition table stored on disk or computed on the fly.
- Parameters:
- modeldynamite.model.Model object, optional
Determines which model is used for the plot. If
None, the minimum chi^2 model is used (the setting in the configuration file’s parameter settings is used to determine which chi^2 is used). The default is None.- max_rfloat, optional
The maximum radius [arcsec] to show in the plot. If
None, it is set to the maximum radius of the orbit library. The default is None.- max_zfloat, optional
The maximum height [arcsec] to show in the plot. If
None, it is set to the maximum height of the orbit library. The default is None.- col_scalestr, optional
The scale of the colorbar. Options are ‘log’ or ‘linear’. The default is ‘log’.
- componentsstr or list-like, optional
Specifies which orbital components to include in the plot. If ‘all’, all orbits are included in the plot without any breakdown by component. If ‘each’, separate plots are created for each component found in the decomposition table and the components’ nomenclature is given by the names parameter. Alternatively, a list of component names can be provided. In that case, individual component plots are generated and the component nomenclature is determined automatically. The default is ‘all’.
- namesstr, optional
This parameter is ONLY relevant if components=’each’. It selects the nomenclature of the component names: ‘bulgedisk’ selects [‘thin_d’, ‘thick_d’, ‘disk’, ‘cr_thin_d’, ‘cr_thick_d’, ‘cr_disk’, ‘bulge’, ‘all’], ‘hotcold’ selects [‘cold’, ‘warm’, ‘cold+warm’, ‘cr_cold’, ‘cr_warm’, ‘cr_cold+warm’, ‘hot’, ‘all’]. The default is ‘bulgedisk’.
- figtypestr, optional
File type extension to save the plot. The default is
'.png'.- Returns
- ——-
- matplotlib.figure.Figure
The created plot.
- Raises:
- ValueError
If col_scale is neither ‘log’ nor ‘linear’.
- ValueError
If components contains invalid component names.
- shiftedColorMap(cmap, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap')¶
Function to offset the “center” of a colormap. Useful for data with a negative min and positive max and you want the middle of the colormap’s dynamic range to be at zero.
- Parameters:
- cmapThe matplotlib colormap to be altered
- startOffset from lowest point in the colormap’s range.
Defaults to 0.0 (no lower offset). Should be between 0.0 and midpoint.
- midpointThe new center of the colormap. Defaults to
0.5 (no shift). Should be between 0.0 and 1.0. In general, this should be 1 - vmax / (vmax + abs(vmin)) For example if your data range from -15.0 to +5.0 and you want the center of the colormap at 0.0, midpoint should be set to 1 - 5/(5 + 15)) or 0.75
- stopOffset from highest point in the colormap’s range.
Defaults to 1.0 (no upper offset). Should be between midpoint and 1.0.
- nameThe name of the new colormap, the default is ‘shiftedcmap’.
- Returns:
- newcmapThe new colormap.
- exception plotter.ReorderLOSVDError¶
Inheritance Diagram¶
