{"id":19568040,"url":"https://github.com/scantle/massplot","last_synced_at":"2025-02-26T10:16:02.836Z","repository":{"id":160643830,"uuid":"90156562","full_name":"scantle/massplot","owner":"scantle","description":"A matplotlib wrapper for rapidly creating simple plots. Takes advantage of reusing plot features and just updating data. Contains some special methods for chemistry-based plots.","archived":false,"fork":false,"pushed_at":"2020-08-06T20:59:50.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-09T01:48:24.678Z","etag":null,"topics":["matplotlib","pdf-generation","plotting","python27"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scantle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-03T14:12:48.000Z","updated_at":"2020-08-06T20:59:53.000Z","dependencies_parsed_at":"2023-05-11T10:45:30.142Z","dependency_job_id":null,"html_url":"https://github.com/scantle/massplot","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scantle%2Fmassplot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scantle%2Fmassplot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scantle%2Fmassplot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scantle%2Fmassplot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scantle","download_url":"https://codeload.github.com/scantle/massplot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240831380,"owners_count":19864718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["matplotlib","pdf-generation","plotting","python27"],"created_at":"2024-11-11T05:43:21.692Z","updated_at":"2025-02-26T10:16:02.718Z","avatar_url":"https://github.com/scantle.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# massplot\nA matplotlib wrapper for rapidly creating simple plots. Takes advantage of reusing plot features and just updating data. Contains some special methods for chemistry-based plots.\n\n## Basic Intended Operation\nFirst, a plot object must be initialized using massplot.create(). The constructor method accepts some basic plot parameters to establish the axes of the plot.\n\n```python\nimport massplot\n\nplot_obj = massplot.create(xlims = [0.1, 100],\n                            ylims = [0, 1000],\n                            xlabel = 'X axis',\n                            ylabel = 'Y axis',\n                            xscale ='log',\n                            yscale ='linear',\n                            figwidth = 11,\n                            figheight = 8.5)\n```\n\nWe don't want to add data to the plot yet - but we do want to create some features that can be used to hold data later on. Colors will be automatically assigned, or can be passed as an argument, but the symbols/style must be passed. You can specify if a feature should be included in the legend (default is `inlegend = True`) Here is a brief example of some of the feature-adding methods in massplot. Each returns the index (indices) of the added features, for refencing during updates.\n```python\nplot_obj.add_feature(style = '--^', label = 'Triangle Line', inlegend = True, empty = False)\nplot_obj.add_features(num_features = 2, style = '--o', inlegend = True)\nplot_obj.add_features_same_color(num_features = 2, style = 'o', inlegend = True)\n```\nFor adding lots of chemistry features - number of locations per plot, and how many chemical analytes will displayed from each well. In the example below, 12 features would be created - three analytes for every well, with an extra non-detect (ND) feature for each (2 * 3 * 2). Non-detect features use a empty marker (e.g. a hollow circle) of the same color.\n```python\nplot_obj.mass_add_chem(num_locs = 2, num_analytes = 3, symbols, nd=True)\n\n# Similarily, add two features\nplot_obj.add_ND_pair_feature(style=='o')\n```\nNext, the legend and a minimap (for data with spatial relationships) can be added. The minimap creates a smaller scatterplot of locations on top of the first plot, and can accept shapefile `pyshp` objects (in a list) to add to the plot. \n```python\nplot_obj.create_legend(loc = 'lower right', size = 7, ncol = 1)\n\n# First arguments are map location in the order: right, bottom, width, height\nplot_obj.create_minimap(.125, .11, .185, .18,\n                        x = data['X'], y = data['Y'],\n                        xbuffer = 100, ybuffer = 100,\n                        xy_color = 'grey', xy_size = 1,\n                        shapelist=[roads, rails], shapecolors=['silver', 'brown'])\n```\n### Data update loop\nFrom here, you can loop over the data and update features. This is a somewhat involved process that hopefully will be simplified in future versions. The main crux is deciding how to keep track of how many features have been updated, and how many have been not (and should therefore be masked from the current plot). If every plot has the same number of features (e.g. every plot contains chemistry data from 2 wells) its easier. However, this is not always easy. Below is an example of a data update loop routine.\n\n```python\nfor locations in plot_list:\n    subset_data = data[data['location'].isin(locations)] # Pandas dataframe\n    \n    # Update plot title\n    plot_obj.set_title(', '.join(locations)) # Puts a comma and a space between location names\n    \n    # Update lines\n    for i, loc in enumerate(locations):\n        # Update one feature for each location\n        plot_obj.update_feature(feature_num = i,\n                                subset_data[subset_data['location]==loc, 'Date'],\n                                subset_data[subset_data['location]==loc, 'Value'],\n                                label = loc)\n    # If there's leftover features, you should mask them. An example method for tracking is shown here.\n    if (len(plot_obj.feature_list) \u003e len(locations)):\n        extra_features = len(plot_obj.feature_list) - len(locations)\n        plot_obj.mask_feature(len(locations)+1, len(locations) + extra_features - 1)\n    \n    # Update the legend\n    plot_obj.update_legend()\n    \n    # Update the minimap location\n    locx = subset_data['X'].unique()\n    locy = subset_data['Y'].unique()\n    plot_obj.minimap_current_loc(locx, locy, 'red', 3)\n    \n    # Add the plot to an open pdf object:\n    plot_obj.add_to_pdf(pdf_object)\n```\nmassplot was written with PDFs in mind, but obviously the matplotlib library can output into a variety of formats.\n\n## massplot Motivation\n`matplotlib` creates great looking plots - especially with a good [style sheet](https://tonysyu.github.io/raw_content/matplotlib-style-gallery/gallery.html). But it's not really set up to rapidly create endless plots for output, instead focusing on interactive features. While other more optimized plotting packages exist, a common solution to speeding up `matplotlib` is to avoid re-drawing elements of plots and instead simply updating the data of the plot \"artists\". However, this can be cumbersome and timely to set up. `massplot` provides some structure for effectively using this method and compressing code length.\n\n## Package requirements\nPython 2.7X, 3.5+\n- matplotlib\n- pandas (barely - checks to see if you're passing a series in a few methods)\n- descartes (for shapefiles)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscantle%2Fmassplot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscantle%2Fmassplot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscantle%2Fmassplot/lists"}