Autofig Objects


In [1]:
import autofig
import numpy as np
import astropy.units as u

autofig works by creating a hierarchy of objects which dictates how a figure should be rendered. These exist at three main levels:

  • Figure
  • Axes
    • AxesDimension (i, x, y, z, c, s)
  • Call (Plot or Mesh)
    • CallDimension (i, x, y, z, c, s)

Calling autofig.plot is simply a shortcut to accessing a built-in Figure object. We can access this object via autofig.gcf() (get current figure) at anytime, or can call the plot method of an instantiated Figure directly.


In [2]:
autofig.reset()
autofig.plot(x=[1,2,3], xunit='s', y=[1,2,3], c=[1,2,3], i='x', uncover=True)
autofig.gcf()


Out[2]:
<Figure | 1 axes | 1 call(s)>

In [3]:
figure = autofig.Figure()
figure.plot(x=[1,2,3], xunit='s', y=[1,2,3], c=[1,2,3], i='x', uncover=True)
figure


Out[3]:
<Figure | 1 axes | 1 call(s)>

Figure

Options

The Figure object holds the collection of Axes objects and is in charge of the subplot layout. As such, it does not currently accept or hold many options.

Methods

The Figure object has the following methods:

  • plot
  • mesh (not yet implemented)
  • reset_draw
  • draw
  • animate
  • add_axes
  • add_call

From the Figure object, you can access the list of children axes:


In [4]:
figure.axes


Out[4]:
<AxesGroup | 1 items | >

as well as the list of all Call objects in those axes:


In [5]:
figure.calls


Out[5]:
<PlotGroup | 1 items | >

Axes


In [6]:
axes = figure.axes[0]
axes


Out[6]:
<Axes | 1 call(s) | dims: c>

Options

equal_aspect


In [7]:
axes.equal_aspect


Out[7]:
False

pad_aspect


In [8]:
axes.pad_aspect


Out[8]:
False

Methods

The Axes object has the following methods:

  • draw
  • add_call

From the Axes object, you can access the parent Figure or a list of the children Call objects


In [9]:
axes.figure


Out[9]:
<Figure | 1 axes | 1 call(s)>

In [10]:
axes.calls


Out[10]:
<PlotGroup | 1 items | >

As well as any of its dimensions (i, x, y, z)


In [11]:
axes.x


Out[11]:
<x | limits: (None, None) | type: time | label: >

Or a combination of the cartesian dimensions


In [12]:
axes.xyz


Out[12]:
<AxDimensionGroup | 3 items | directions: x, y, z | labels: , , >

In [13]:
axes.xy


Out[13]:
<AxDimensionGroup | 2 items | directions: x, y | labels: , >

or a list of its color/size dimensions (cs, ss)


In [14]:
axes.cs


Out[14]:
<AxDimensionGroup | 1 items | directions: c | labels: >

AxesDimension


In [15]:
ad = axes.x
ad


Out[15]:
<x | limits: (None, None) | type: time | label: >

Options

unit

The unit in the AxesDimension will be those actually plotted (i.e. all values will be converted from their stored units to these)


In [16]:
ad.unit


Out[16]:
$\mathrm{s}$

In [17]:
ad.unit='d'
ad.unit


Out[17]:
$\mathrm{d}$

pad

Padding provided to an AxesDimension will override the default padding on the Axes itself. Here since it has not been set yet, it defaults to the value from the Axes


In [18]:
ad.pad


Out[18]:
0.1

In [19]:
axes.pad=0.05
ad.pad


Out[19]:
0.1

In [20]:
ad.pad=0.15
axes.pad=0.08
ad.pad


Out[20]:
0.15

lim

Limits will adhere to the padding of the same AxesDimension.


In [21]:
ad.lim


Out[21]:
(None, None)

In [22]:
ad.pad=0.0
ad.lim


Out[22]:
(None, None)

label


In [23]:
ad.label


Out[23]:
''

In [24]:
ad.label='mylabel'
ad.label_with_units


Out[24]:
'mylabel [$\\mathrm{d}$]'

The AxesDimension object has a link back to its parent Axes


In [25]:
ad.axes


Out[25]:
<Axes | 1 call(s) | dims: c>

Cyclers


In [26]:
lsc = axes.linestylecycler
lsc


Out[26]:
<linestylecycler | cycle: ['solid', 'dashed', 'dotted', 'dashdot'] | used: []>

Options

cycle

The cycle defines the order at which the properties will be drawn.


In [27]:
lsc.cycle


Out[27]:
['solid', 'dashed', 'dotted', 'dashdot']

If desired, you can change this default order (Note: the cycle can be shorter than the original, but you cannot add new items)


In [28]:
lsc.cycle = ['dashed', 'dotted', 'dashdot', 'solid']

Plot (Call)


In [29]:
plot = axes.calls[0]
plot


Out[29]:
<Call:Plot | dims: i, x, y, c>

Options

kwargs (sent on to matplotlib, when possible)


In [30]:
plot.kwargs


Out[30]:
{}

highlight


In [31]:
plot.highlight


Out[31]:
True

In [32]:
plot.highlight_marker


Out[32]:
'o'

If None, highlight_size will default to size


In [33]:
plot.highlight_size


Out[33]:
0.04

In [34]:
plot.highlight_linestyle


Out[34]:
'None'

If None, highlight_color will default to color


In [35]:
plot.highlight_color

uncover


In [36]:
plot.uncover


Out[36]:
True

In [37]:
plot.uncover=True
ad.get_lim(i=1.5)


Out[37]:
(1.1574074074074073e-05, 3.472222222222222e-05)

In [38]:
plot.uncover=False
ad.get_lim(i=1.5)


Out[38]:
(1.1574074074074073e-05, 3.472222222222222e-05)

consider for limits


In [39]:
plot.consider_for_limits=False
ad.get_lim(i=1.5)


Out[39]:
(None, None)

In [40]:
plot.consider_for_limits=True
ad.get_lim(i=1.5)


Out[40]:
(1.1574074074074073e-05, 3.472222222222222e-05)

Methods

The Plot object has the following methods:

  • draw

The Plot object has a link back to its parent Axes and grandparent Figure objects.


In [41]:
plot.axes


Out[41]:
<Axes | 1 call(s) | dims: c>

In [42]:
plot.figure


Out[42]:
<Figure | 1 axes | 1 call(s)>

PlotDimension


In [43]:
pd = plot.x
pd


Out[43]:
<x | len: 3 | type: time | label: None>

Options

unit

The unit in PlotDimension holds the units of the provided array. These will be converted to the necessary units for plotting. Changing this unit does not do any converting of the array, so change with caution.


In [44]:
pd.unit


Out[44]:
$\mathrm{s}$

label


In [45]:
pd.label

Methods

get_value

In addition to the 'value' property, get_value will handle hiding values after 'i' and interpolating to that exact value.


In [46]:
pd.get_value()


Out[46]:
array([1, 2, 3])

In [47]:
plot.uncover=False
pd.get_value(i=1.5)


Out[47]:
array([1, 2, 3])

In [48]:
plot.uncover=True
pd.get_value(i=1.5)


Out[48]:
array([1. , 1.5])

get_error (for cartesian only)

Same as above for get_value, except interpolation will not be used for the final value.

interpolate_at_i

interpolate_at_i simply interpolates the value for a given value of the independent variable


In [49]:
pd.interpolate_at_i(i=1.5)


Out[49]:
1.5

The CallDimension objects have shortcuts back to their parent Call (Plot or Mesh)


In [50]:
pd.call


Out[50]:
<Call:Plot | dims: i, x, y, c>