Version 3.0.3
matplotlib
Fork me on GitHub

matplotlib.category

Module that allows plotting of string "category" data. i.e. plot(['d', 'f', 'a'],[1, 2, 3]) will plot three points with x-axis values of 'd', 'f', 'a'.

See Plotting categorical variables for an example.

The module uses Matplotlib's matplotlib.units mechanism to convert from strings to integers, provides a tick locator and formatter, and the class:UnitData that creates and stores the string-to-integer mapping.

class matplotlib.category.StrCategoryConverter[source]

Bases: matplotlib.units.ConversionInterface

static axisinfo(unit, axis)[source]

Sets the default axis ticks and labels

Parameters:
unit : UnitData

object string unit information for value

axis : axis

axis for which information is being set

Returns:
axisinfo : AxisInfo

Information to support default tick labeling

.. note: axis is not used
static convert(value, unit, axis)[source]

Converts strings in value to floats using mapping information store in the unit object.

Parameters:
value : string or iterable

value or list of values to be converted

unit : UnitData

object string unit information for value

axis : axis

axis on which the converted value is plotted

Returns:
mapped_ value : float or ndarray[float]
.. note:: axis is not used in this function
static default_units(data, axis)[source]

Sets and updates the axis units.

Parameters:
data : string or iterable of strings
axis : axis

axis on which the data is plotted

Returns:
class:~.UnitData~

object storing string to integer mapping

class matplotlib.category.StrCategoryFormatter(units_mapping)[source]

Bases: matplotlib.ticker.Formatter

String representation of the data at every tick

Parameters:
units_mapping : Dict[Str, int]

string:integer mapping

class matplotlib.category.StrCategoryLocator(units_mapping)[source]

Bases: matplotlib.ticker.Locator

tick at every integer mapping of the string data

Parameters:
units_mapping : Dict[str, int]

string:integer mapping

tick_values(vmin, vmax)[source]

Return the values of the located ticks given vmin and vmax.

Note

To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance:

>>> print(type(loc))
<type 'Locator'>
>>> print(loc())
[1, 2, 3, 4]
class matplotlib.category.UnitData(data=None)[source]

Bases: object

Create mapping between unique categorical values and integer ids.

Parameters:
data: iterable

sequence of string values

update(data)[source]

Maps new values to integer identifiers.

Parameters:
data: iterable

sequence of string values

Raises:
TypeError

If the value in data is not a string, unicode, bytes type