DataGeometry objects (geo)

The DataGeometry object is the hypertools data object class. A geo contains the data, figure handles, and transform functions used to create a plot. Note that this class should not be called directly, but is used by the hyp.plot function to create a plot object.

In this tutorial we will explore the features of a geo and how it may be used.

Import Hypertools


In [ ]:
import hypertools as hyp
import seaborn as sb

%matplotlib inline

Load your data

In this case, we have used one of the sample datasets built into the package.


In [ ]:
geo = hyp.load('mushrooms')

Plot it

We can plot a geo by calling the plot method


In [ ]:
geo.plot()

Exploring the geo

Hypertools version

The version field contains the version number of hypertools that the geo was generated with.


In [ ]:
geo.version

Data and plot

The data field contains the raw data.


In [ ]:
geo.data.head()

Transformed data

The xform_data field contains the data that have been transformed according to the user-specified normalize, reduce, and align options (in this case, the data was automatically reduced to 3 dimensions for plotting when we called hyp.plot).


In [ ]:
geo.xform_data

Normalize, reduce and align metadata

The reduce, align and normalize fields contain information about the model and parameters used in each of the analyses.

The reduce and align fields contain dictionaries with the model information and the normalize field contains a string.


In [ ]:
print(geo.normalize)
print(geo.reduce)
print(geo.align)

Plotting axes and animations

The ax and line_ani fields hold the plot axes and the animation setting (in this case None) for plotting, respectively.

To read more about the plot axes and line animation objects and their utility, see the matlplotlib documentation for axes and animations, respectively.


In [ ]:
geo.ax

In [ ]:
geo.line_ani

Plotting with geos

You can also generate a new plot (a new geo) from data stored in the geo using geo.plot.

This plotting feature accepts all of the keyword arguments supported by hypertools.plot.

First, let's plot without making any changes.


In [ ]:
geo.plot()

Now, let's change the plot using some keyword arguments.

In the example below, the data are re-transformed using all of the same options as in the original plot, but with the number of dimensions specified by the reduce model set to 2.


In [ ]:
geo.plot(ndims = 2)

Tranforming data using geos

An additional feature afforded by geos is the ability to later analyze other datasets using the same transformations performed on the original data in the geo. That is, whatever normalization, alignment, and reduction parameters were used on the original data in the geo can be quickly and easily applied to any new dataset using a single line of code!

This allows for easy comparison of multiple datasets. Here, we load a built in dataset (the weights dataset) and apply the transform from the geo data to the first element of weights.


In [ ]:
weights = hyp.load('weights_avg').get_data()
transformed = geo.transform(weights)

We can use heatmaps to visualized an element of the new data before and after it has been transformed by the same means as the geo data.


In [ ]:
ax = sb.heatmap(weights[0])

In [ ]:
ax = sb.heatmap(transformed[0])

Saving geos

You can also easily save a geo using geo.save. The geo will save as a 'geo' file, which is a dictionary containing the elements of a data geometry object saved in the hd5 format using deepdish.

To specify the compression type, pass a string to the compression argument, as below. See the deepdish documentation for the full list of compression options: http://deepdish.readthedocs.io/en/latest/api_io.html#deepdish.io.save


In [ ]:
# geo.save('MyGeoFile')
# geo.save('MyGeoFile', compression = 'blosc')