-
Notifications
You must be signed in to change notification settings - Fork 245
Description
In two gallery examples categorical data (without order) is displayed by using color-coding for the categories:
The data (csv file) is loaded into a pandas dataframe and the column of interest is converted to categorical data type. A discrete colormap in categorical format is set up via the pygmt.makecpt() function (+c through color_model). For plotting the symbols with the corresponding fill color the categorical number code is passed through the color parameter of the pygmt.Figure.plot() method.
I recommend to clarify that by default the labels for the colorbar must be given in alphabetical order. If one wants labels in non-alphabetical order, e. g. increasing or decreasing order for displaying categorical data with order, the categorical number code has to be adjusted by the user. For instance, to get 'poor, fair, good' instead of 'fair, good, poor' (dataframe 'df' with column 'quality'):
df.quality = df.quality.cat.set_categories(['poor','fair','good'], ordered = True)
The label order (comma-separated list) passed through color_model in the pygmt.makecpt() function has no effect on the plotting itself, but affects only the colorbar labels.