matplotlib.category#
Plotting of string "category" data:plot(['d','f','a'],[1,2,3]) willplot three points with x-axis values of 'd', 'f', 'a'.
SeePlotting categorical variables for anexample.
The module uses Matplotlib'smatplotlib.units mechanism to convert fromstrings to integers and provides a tick locator, a tick formatter, and theUnitData class that creates and stores the string-to-integer mapping.
- classmatplotlib.category.StrCategoryConverter[source]#
Bases:ConversionInterface
- staticaxisinfo(unit,axis)[source]#
Set 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:
AxisInfoInformation to support default tick labeling
- staticconvert(value,unit,axis)[source]#
Convert strings invalue to floats using mapping information storedin theunit object.
- Parameters:
- valuestr or iterable
Value or list of values to be converted.
- unit
UnitData An object mapping strings to integers.
- axis
Axis The axis on which the converted value is plotted.
- Returns:
- float or
ndarray of float
- staticdefault_units(data,axis)[source]#
Set and update theAxis units.
- Parameters:
- datastr or iterable of str
- axis
Axis axis on which the data is plotted
- Returns:
UnitDataobject storing string to integer mapping
- classmatplotlib.category.StrCategoryFormatter(units_mapping)[source]#
Bases:Formatter
String representation of the data at every tick.
- Parameters:
- units_mappingdict
Mapping of category names (str) to indices (int).
- format_ticks(values)[source]#
Return the tick labels for all the ticks at once.
- classmatplotlib.category.StrCategoryLocator(units_mapping)[source]#
Bases:Locator
Tick at every integer mapping of the string data.
- Parameters:
- units_mappingdict
Mapping of category names (str) to indices (int).
- tick_values(vmin,vmax)[source]#
Return the values of the located ticks givenvmin andvmax.
Note
To get tick locations with the vmin and vmax values definedautomatically for the associatedaxis simply callthe Locator instance:
>>>print(type(loc))<type 'Locator'>>>>print(loc())[1, 2, 3, 4]
- classmatplotlib.category.UnitData(data=None)[source]#
Bases:object
Create mapping between unique categorical values and integer ids.
- Parameters:
- dataiterable
sequence of string values
- update(data)[source]#
Map new values to integer identifiers.
- Parameters:
- dataiterable of str or bytes
- Raises:
- TypeError
If elements indata are neither str nor bytes.