Skip to main content

A python package for creating JSONGrapher Records.

Project description

JSONGrapherRC

A python package for creating JSONGrapher Records

To use JSONGrapherRC, first install it using pip:

pip install JSONGrapherRC[COMPLETE]

Alternatively, you can download the directory directly.
It is easiest to then follow the example file to learn.

1. Preparing to Create a Record

Let's create an example where we plot the height of a pear tree over several years. Assuming a pear tree grows approximately 0.40 meters per year, we'll generate sample data with some variation.

x_label_including_units = "Time (years)"
y_label_including_units = "Height (m)"
time_in_years = [0, 1, 2, 3, 4]
tree_heights = [0, 0.42, 0.86, 1.19, 1.45]

2. Creating and Populating a New JSONGrapher Record

The easiest way to start is with the create_new_JSONGrapherRecord() function. While you can instantiate the JSONGrapherRecord class directly, this function is generally more convenient. We'll create a record and inspect its default fields.

try:
    from JSONGRapherRC import JSONRecordCreator  # Normal usage
except ImportError:
    import JSONRecordCreator  # If the class file is local

Record = JSONRecordCreator.create_new_JSONGrapherRecord()
Record.set_comments("Tree Growth Data collected from the US National Arboretum")
Record.set_datatype("Tree_Growth_Curve")
Record.set_x_axis_label_including_units(x_label_including_units)
Record.set_y_axis_label_including_units(y_label_including_units)
Record.add_data_series(series_name="pear tree growth", x_values=time_in_years, y_values=tree_heights, plot_type="scatter_spline")
Record.set_graph_title("Pear Tree Growth Versus Time")

3. Exporting to File

We now have a JSONGrapher record! We can export it to a file, which can then be used with JSONGrapher.

Record.export_to_json_file("ExampleFromTutorial.json")
Record.print_to_inspect()

Expected Output:

JSONGrapher Record exported to, ./ExampleFromTutorial.json
{
    "comments": "Tree Growth Data collected from the US National Arboretum",
    "datatype": "Tree_Growth_Curve",
    "data": [
        {
            "name": "pear tree growth",
            "x": [0, 1, 2, 3, 4],
            "y": [0, 0.42, 0.86, 1.19, 1.45],
            "type": "scatter",
            "line": { "shape": "spline" }
        }
    ],
    "layout": {
        "title": "Pear Tree Growth Versus Time",
        "xaxis": { "title": "Time (year)" },
        "yaxis": { "title": "Height (m)" }
    }
}

We can also plot the data using Matplotlib and export the plot as a PNG file.

Record.plot_with_matplotlib()
Record.export_to_matplotlib_png("ExampleFromTutorial")

And we can create an interactive graph in a browser with plotly:

Record.plot_with_plotly() #Try hovering the mouse over points in plotly figures!

JSONGRapher record plotted using matplotlib

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsongrapherrc-1.8.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsongrapherrc-1.8-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file jsongrapherrc-1.8.tar.gz.

File metadata

  • Download URL: jsongrapherrc-1.8.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for jsongrapherrc-1.8.tar.gz
Algorithm Hash digest
SHA256 3d51dc58e24f99f9d83c0bf3d58f70baefb0bbdc81e31f842200da827ae475e5
MD5 460a88594ab966f59f33478912407a17
BLAKE2b-256 1ae1b77550070dfeca636760d689a01afb3ae724ee80ab2425fcbccfa400a8d4

See more details on using hashes here.

File details

Details for the file jsongrapherrc-1.8-py3-none-any.whl.

File metadata

  • Download URL: jsongrapherrc-1.8-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for jsongrapherrc-1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 12870f52f87d6d7b8efdca8a6a28f6936d015308f8777c8c9525661c6a611e7b
MD5 d63cba7e1aa386999361fd401f27c4b4
BLAKE2b-256 4a05d83b5b85baabf7e3c1e4c75b6b3cc4351012cfb549644e9960717b6a9b57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page