Package: data-morph-ai
Data Morph transforms an input dataset of 2D points into select shapes, while preserving the summary statistics to a given number of decimal points through simulated annealing.InstallationData Morph can be installed from PyPI usingpip:$pipinstalldata-morph-aiAlternatively, Data Morph can be installed withcondaby specifying theconda-forgechannel:$condainstall-cconda-forgedata-morph-aiUsageOnce installed, Data Morph can be used on the command line or as an importable Python package. Below are some examples; be sure to check out thedocumentationfor more information.Command Line UsageRundata-morphon the command line:$data-morph--start-shapepanda--target-shapestarThis produces the animation in the newly-createdmorphed_datadirectory within your current working directory (shown above).See all available CLI options by passing in--help:$data-morph--helpPython UsageTheDataMorpherclass performs the morphing from aDatasetto aShape. Anypandas.DataFramewith numeric columnsxandycan be aDataset. Use theDataLoaderto create theDatasetfrom a file or use a built-in dataset:fromdata_morph.data.loaderimportDataLoaderdataset=DataLoader.load_dataset('panda')For morphing purposes, all target shapes are placed/sized based on aspects of theDatasetclass.
All shapes are accessible via theShapeFactoryclass:fromdata_morph.shapes.factoryimportShapeFactoryshape_factory=ShapeFactory(dataset)target_shape=shape_factory.generate_shape('star')With theDatasetandShapecreated, here is a minimal example of morphing:fromdata_morph.morpherimportDataMorphermorpher=DataMorpher(decimals=2,in_notebook=False,# whether you are running in a Jupyter Notebookoutput_dir='data_morph/output',)result=morpher.morph(start_shape=dataset,target_shape=target_shape)Note that theresultvariable in the above code block is apandas.DataFrameof the data after completing the specified iterations of the simulated annealing process. TheDataMorpher.morph()method is also saving plots to visualize the output periodically and make an animation; these end up indata_morph/output, which we set asDataMorpher.output_dir.In this example, we morphed the built-in pandaDatasetinto the starShape. Be sure to try out the other built-in options:TheDataLoader.AVAILABLE_DATASETSattribute contains a list of available datasets, which are also visualized in theDataLoaderdocumentation.TheShapeFactory.AVAILABLE_SHAPESattribute contains a list of available shapes, which are also visualized in theShapeFactorydocumentation.AcknowledgementsThis code has been altered by Stefanie Molin (@stefmolin) to work for other input datasets by parameterizing the target shapes with information from the input shape. The original code works for a specific dataset called the "Datasaurus" and was created for the paperSame Stats, Different Graphs: Generating Datasets with Varied Appearance and Identical Statistics through Simulated Annealingby Justin Matejka and George Fitzmaurice (ACM CHI 2017).The paper and video can be found on the Autodesk Research websitehere. The version of the code placed on GitHub atjmatejka/same-stats-different-graphs, served as the starting point for the Data Morph code base, which is on GitHub atstefmolin/data-morph.Read more about the creation of Data Morphhere.CitationsIf you use this software, please cite both Data Morph (DOI:10.5281/zenodo.7834197) andSame Stats, Different Graphs: Generating Datasets with Varied Appearance and Identical Statistics through Simulated Annealingby Justin Matejka and George Fitzmaurice (ACM CHI 2017).