Package: palette-diagram
Palette diagramA palette diagram is a visualization tool for a large number of categorical datasets, each comprising several categories.Linear palette diagramThis is a stream plot, which is usually used for plotting time series data.
Each categorical dataset is stacked vertically, and these stacked plots are aligned horizontally so that the neighboring datasets have similar vertical patterns.Circular palette diagramEach categorical dataset is represented along the radial coordinate: Each layer corresponds to a category and the thickness represents the normalized (or unnormalized) quantity within a category.
The set of categorical data is aligned along the angular coordinate.The central part shows indicates the color of the dominant category within a categorical dataset (i.e., the maximum a posteriori estimate).Installationpalette-diagramcan be installed from PyPI:pip install palette-diagramDemoYou can find a demohere.UsageThis function generates a linear or circular palette diagram from a data table.importpandasaspdimportpalette_diagramasptdf=pd.read_csv('your_dataset.csv')pt.palette_diagram(df)InputA data tabledfinpandasDataFrame.
Each row represents a categorical dataset.
Here is how the DataFrame should look like:category Acategory Bcategory Ccategory C1531282404511291183nan............The (i,k) element in the DataFrame represents a quantity forkth category inith dataset.The DataFrame must have column names representing the category labels.The value of each cell has to be non-negative.A dataset is allowed to have missing cells (nan). The missing cells are filled with zeros.Input with dataset indicesIf the DataFrame has a column representing the index for each row (i.e., dataset), the column will be omitted in a palette diagram, and the indices will be used as the dataset ID indata_ordering.csv. For example, if your DataFrame looks likedata_idcategory Acategory Bcategory Ccategory CA001153128A00224045112A00391183nan...............then you can generate a palette diagram anddata_ordering.csvbypt.palette_diagram(df,index='data_id')OutputA linear palette diagram or circular palette diagram.Optional parametersargumenttype/valuesdefault valuedescriptionpalette_type{'circular', 'linear'}'circular''circular': circular palette diagram'linear': linear palette diagramn_neighborsinteger100A hyperparameter for the linear palette diagram (see below for details)n_epochsinteger100A hyperparameter for the circular palette diagram (see below for details)lrfloat0.0005A hyperparameter for the circular palette diagram (see below for details)normbooleanTrueIf True, each categorical dataset (row in the datamatrix) will be normalized to unity. The diagram has non-uniform layer thickness whennorm=False.exportbooleanTrueIf True, the palette diagram will be saved as a PDF file in./output/.export_tablebooleanTrueIf True, the ordering of the datasets will be saved as a csv in./output/.category_labelslist of category labelsNoneIf provided, you can manually control the color assignment of each category by specifying the order of category labels.cmap_namestringNoneIf a qualitative color palette inmatplotlibis provided, the specified color map is will be used.remove_empty_sets{0,1,2,-1}-10: Remove all empty (zero-valued) rows (data)1: Remove all empty (zero-valued) columns (categories)2: Remove all empty (zero-valued) rows and columns-1: IgnoredindexstringNoneIf provided, the specified column in the DataFrame will be used as a set of dataset indices. If None, a set of consecutive numbers is assigned as the dataset indices.Order optimizationlinear palette diagramIn the linear palette diagram, the order of the datasets are optimized through ISOMAP.n_neighborsis a hyperparameter used to construct a k-nearest neighbor graph in ISOMAP.circular palette diagramIn the circular palette diagram, the stochastic gradient descent (SGD) method is used for the order optimization.n_epochsandlrare hyperparameters for the SGD:n_epochsis the number of epochs andlris the learning rate.We strongly recommend users to try various values of these hyperparameters, as the appropriate value varies depending on the input data table.ReferencesPlease cite the following paper when you use the palette diagram:Chihiro Noguchi and Tatsuro Kawamoto, "Palette diagram: A Python package for visualization of collective categorical data,"arXiv:2011.01934(2020).You can find more details about the (linear) palette diagram in the following article:Chihiro Noguchi and Tatsuro Kawamoto, "Evaluating network partitions through visualization,"arXiv:1906.00699,unpublished(2019).