matplotlib.category
Plotting of string "category" data: 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 and provides a tick locator, a tick formatter, and the UnitData
class that creates and stores the string-to-integer mapping.
-
class matplotlib.category.StrCategoryConverter
[source] -
Bases:
matplotlib.units.ConversionInterface
-
static axisinfo(unit, axis)
[source] -
Set the default axis ticks and labels.
Parameters: -
unitUnitData
-
object string unit information for value
-
axisAxis
-
axis for which information is being set
Returns: -
axisinfoAxisInfo
-
Information to support default tick labeling
-
-
static convert(value, unit, axis)
[source] -
Convert strings in value to floats using mapping information stored in the unit object.
Parameters: -
valuestr or iterable
-
Value or list of values to be converted.
-
unitUnitData
-
An object mapping strings to integers.
-
axisAxis
-
The axis on which the converted value is plotted.
Note
axis is unused.
Returns: -
mapped_valuefloat or ndarray[float]
-
-
-
class matplotlib.category.StrCategoryFormatter(units_mapping)
[source] -
Bases:
matplotlib.ticker.Formatter
String representation of the data at every tick.
Parameters: -
units_mappingDict[Str, int]
-
format_ticks(self, values)
[source] -
Return the tick labels for all the ticks at once.
-
-
class matplotlib.category.StrCategoryLocator(units_mapping)
[source] -
Bases:
matplotlib.ticker.Locator
Tick at every integer mapping of the string data.
Parameters: -
units_mappingDict[str, int]
-
tick_values(self, 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: -
dataiterable
-
sequence of string values
-
update(self, data)
[source] -
Map new values to integer identifiers.
Parameters: -
dataiterable
-
sequence of string values
Raises: - TypeError
-
If the value in data is not a string, unicode, bytes type
-
-
© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.2.2/api/category_api.html