cowpatch.base_elements
Module Contents
Classes
fundamental object of cowpatch, encapsulates plot objects and |
- class cowpatch.base_elements.patch(*args, grobs=None)[source]
fundamental object of cowpatch, encapsulates plot objects and can be told how to present them
- Parameters
*args (plot objects and patches) – all non-named parameters are expected to be plot objects or lower-level
cow.patch
objects.grobs (list) – list of plot objects and patches. Either
\*args
is empty orgrobs
isNone
.
Notes
Guiding arangement:
In combination with
cow.layout
one can define arrangement of plots and lower-level arangements.For example,
>>> vis_obj = cow.patch(g1,g2,g3) >>> vis_obj += cow.layout(design = np.array([[0,1], ... [2,2]])) >>> vis_obj.show()
See the Layout guide for more detailed examples of functionality.
Nesting:
One can nest cow.patch objects within other cow.patch objects. For example,
>>> vis_obj2 = cow.patch(g4, vis_obj) >>> vis_obj2 += cow.layout(nrow = 1) >>> vis_obj2.show()
Examples
>>> # Necessary libraries for example >>> import numpy as np >>> import cowpatch as cow >>> import plotnine as p9 >>> import plotnine.data as p9_data
>>> g0 = p9.ggplot(p9_data.mpg) +\ ... p9.geom_bar(p9.aes(x="hwy")) +\ ... p9.labs(title = 'Plot 0') >>> g1 = p9.ggplot(p9_data.mpg) +\ ... p9.geom_point(p9.aes(x="hwy", y = "displ")) +\ ... p9.labs(title = 'Plot 1') >>> g2 = p9.ggplot(p9_data.mpg) +\ ... p9.geom_point(p9.aes(x="hwy", y = "displ", color="class")) +\ ... p9.labs(title = 'Plot 2') >>> g3 = p9.ggplot(p9_data.mpg[p9_data.mpg["class"].isin(["compact", ... "suv", ... "pickup"])]) +\ ... p9.geom_histogram(p9.aes(x="hwy"),bins=10) +\ ... p9.facet_wrap("class")
>>> # Basic example: >>> vis_obj = cow.patch(g0,g1,g2) >>> vis_obj += cow.layout(design = np.array([[0,1], ... [2,2]])) >>> vis_obj.show()
>>> # Nesting example: >>> vis_obj2 = cow.patch(g3, vis_obj) >>> vis_obj2 += cow.layout(nrow = 1) >>> vis_obj2.show()
See also
layout
class objects that can aid in defining the layout of plots in
cow.patch
objects
- property layout
defines
layout
that either returns the last addedcow.layout
object or the defaultlayout
if no layout has been explicitly defined
- save(filename, width=None, height=None, dpi=96, _format=None, verbose=None)[source]
save patch to file
- Parameters
filename (str) – local string to save the file to (this can also be at a
io.BytesIO
)width (float) – width of output image in inches (this should actually be associated with the svg…)
height (float) – height of svg in inches (this should actually be associated with the svg…)
dpi (int or float) – dots per square inch, default is 96 (standard)
_format (str) – string of format (error tells options). If provided this is the format used, if None, then we’ll try to use the
filename
extension.verbose (bool) – If
True
, print the saving information. The package default is defined by cowpatch’s own rcParams (the base default isTrue
), which is used if verbose isNone
. See Notes.
- Returns
saves to a file
- Return type
None
Notes
If width and/or height is None, the approach will attempt to define acceptable width and height.
The
verbose
parameter can be changed either directly with definingverbose
input parameter or changingcow.rcParams["save_verbose"]
.See also
io.BytesIO
object that acts like a reading in of bytes
- show(width=None, height=None, dpi=96, verbose=None)[source]
display object from the command line or in a jupyter notebook
- Parameters
width (float) – width of output image in inches (this should actually be associated with the svg…)
height (float) – height of svg in inches (this should actually be associated with the svg…)
dpi (int or float) – dots per square inch, default is 96 (standard)
verbose (bool) – If
True
, print the saving information. The package default is defined by cowpatch’s own rcParams (the base default isTrue
), which is used if verbose isNone
. See Notes.
Notes
If width and/or height is None, the approach will attempt to define acceptable width and height.
The
verbose
parameter can be changed either directly with definingverbose
input parameter or changingcow.rcParams["show_verbose"]
.If run from the command line, this approach leverage matplotlib’s plot render to show a static png version of the image. If run inside a jupyter notebook, this approache presents the actual svg representation.