PyPlot¶
Provides a collection of functions useful in various plotting routines.
-
e13tools.pyplot.
apu2tex
(unit, unitfrac=False)[source]¶ Transform a
Unit
object into a (La)TeX string for usage in aFigure
instance.Parameters: unit ( Unit
object) – Unit to be transformed.Other Parameters: unitfrac (bool. Default: False) – Whether or not to write unit as a LaTeX fraction. Returns: out (string) – String containing unit written in (La)TeX string. Examples
>>> import astropy.units as apu >>> apu2tex(apu.solMass) '\mathrm{M_{\odot}}'
>>> import astropy.units as apu >>> apu2tex(apu.solMass/apu.yr, unitfrac=False) '\mathrm{M_{\odot}\,yr^{-1}}'
>>> import astropy.units as apu >>> apu2tex(apu.solMass/apu.yr, unitfrac=True) '\mathrm{\frac{M_{\odot}}{yr}}'
-
e13tools.pyplot.
center_spines
(centerx=0, centery=0, set_xticker=False, set_yticker=False, ax=None)[source]¶ Centers the axis spines at <centerx, centery> on the axis ax in a
Figure
instance. Centers the axis spines at the origin by default.Other Parameters: - centerx (int or float. Default: 0) – Centers x-axis at value centerx.
- centery (int or float. Default: 0) – Centers y-axis at value centery.
- set_xticker (int, float or False. Default: False) – If int or float, sets the x-axis ticker to set_xticker.
If False, let
Figure
instance decide. - set_yticker (int, float or False. Default: False) – If int or float, sets the y-axis ticker to set_yticker.
If False, let
Figure
instance decide. - ax (
Axes
object or None. Default: None) – IfAxes
object, centers the axis spines of specifiedFigure
instance. If None, centers the axis spines of currentFigure
instance.
-
e13tools.pyplot.
draw_textline
(text, *, x=None, y=None, pos='start top', ax=None, line_kwargs={}, text_kwargs={})[source]¶ Draws a line on the axis ax in a
Figure
instance and prints text on top.Parameters: - text (str) – Text to be printed on the line.
- x (scalar or None) – If scalar, text/line x-coordinate. If None, line covers complete x-axis. Either x or y needs to be None.
- y (scalar or None) – If scalar, text/line y-coordinate. If None, line covers complete y-axis. Either x or y needs to be None.
Other Parameters: - pos ({‘start’, ‘end’}{‘top’, ‘bottom’}. Default: ‘start top’) – If ‘start’, prints the text at the start of the drawn line. If ‘end’, prints the text at the end of the drawn line. If ‘top’, prints the text above the drawn line. If ‘bottom’, prints the text below the drawn line. Arguments must be given as a single string.
- ax (
Axes
object or None. Default: None) – IfAxes
object, draws line in specifiedFigure
instance. If None, draws line in currentFigure
instance. - line_kwargs (dict of
Line2D
properties. Default: {}) – The keyword arguments used for drawing the line. - text_kwargs (dict of
Text
properties. Default: {}) – The keyword arguments used for drawing the text.
-
e13tools.pyplot.
f2tex
(value, *errs, sdigits=4, power=3, nobase1=True)[source]¶ Transform a value into a (La)TeX string for usage in a
Figure
instance.Parameters: value (int or float) – Value to be transformed.
Other Parameters: - errs (int or float) – The upper and lower \(1\sigma\)-errors of the given value. If only a single value is given, value is assumed to have a centered error interval of errs.
- sdigits (int. Default: 4) – Number of significant digits any value is returned with.
- power (int. Default: 3) – Minimum abs(log10(value)) required before all values are written in scientific form. This value is ignored if sdigits forces scientific form to (not) be used.
- nobase1 (bool. Default: True) – Whether or not to include base in scientific form if base=1. This is always False if errs contains at least one value.
Returns: out (string) – String containing value and errs written in (La)TeX string.
Examples
>>> f2tex(20.2935826592) '20.29'
>>> f2tex(20.2935826592, sdigits=6) '20.2936'
>>> f2tex(20.2935826592, power=1) '2.029\cdot 10^{1}'
>>> f2tex(1e6, nobase1=True) '10^{6}'
>>> f2tex(1e6, nobase1=False) '1.000\cdot 10^{6}'
>>> f2tex(20.2935826592, 0.1) '20.29\pm 0.10'
>>> f2tex(20.2935826592, 0.1, 0.2) '20.29^{+0.10}_{-0.20}'
>>> f2tex(1e6, 12, 10) '1.000^{+0.000}_{-0.000}\cdot 10^{6}'
>>> f2tex(1e6, 12, 10, sdigits=6) '1.000^{+0.000}_{-0.000}\cdot 10^{6}'
-
e13tools.pyplot.
q2tex
(quantity, *errs, sdigits=4, power=3, nobase1=True, unitfrac=False)[source]¶ Combination of
f2tex()
andapu2tex()
.Transform a
Quantity
object into a (La)TeX string for usage in aFigure
instance.Parameters: quantity (int, float or
Quantity
object) – Quantity to be transformed.Other Parameters: - errs (int, float or
Quantity
object) – The upper and lower \(1\sigma\)-errors of the given quantity. If only a single value is given, quantity is assumed to have a centered error interval of errs. The unit of errs must be convertible to the unit of quantity. - sdigits (int. Default: 4) – Maximum amount of significant digits any quantity is returned with.
- power (int. Default: 3) – Minimum abs(log10(value)) required before all quantities are written in scientific form. This value is ignored if sdigits forces scientific form to (not) be used.
- nobase1 (bool. Default: True) – Whether or not to include base in scientific form if base=1. This is always False if errs contains a value.
- unitfrac (bool. Default: False) – Whether or not to write unit as a LaTeX fraction.
Returns: out (string) – String containing quantity and errs written in (La)TeX string.
Examples
>>> import astropy.units as apu >>> q2tex(20.2935826592) '20.29'
>>> q2tex(20.2935826592*apu.kg, 1500*apu.g) '20.29\pm 1.50\,\mathrm{kg}'
>>> q2tex(20.2935826592*apu.solMass/apu.yr) '20.29\,\mathrm{M_{\odot}\,yr^{-1}}'
>>> q2tex(20.2935826592*apu.solMass/apu.yr, sdigits=6) '20.2936\,\mathrm{M_{\odot}\,yr^{-1}}'
>>> q2tex(20.2935826592*apu.solMass/apu.yr, power=1) '2.029\cdot 10^{1}\,\mathrm{M_{\odot}\,yr^{-1}}'
>>> q2tex(1e6*apu.solMass/apu.yr, nobase1=True) '10^{6}\,\mathrm{M_{\odot}\,yr^{-1}}'
>>> q2tex(1e6*apu.solMass/apu.yr, nobase1=False) '1.000\cdot 10^{6}\,\mathrm{M_{\odot}\,yr^{-1}}'
>>> q2tex(20.2935826592*apu.solMass/apu.yr, unitfrac=False) '20.29\,\mathrm{M_{\odot}\,yr^{-1}}'
>>> q2tex(20.2935826592*apu.solMass, 1*apu.solMass, unitfrac=True) '20.29\pm 1.00\,\mathrm{M_{\odot}}'
- errs (int, float or