/GSON

Visualize JSON data as plots, pies, bars

Primary LanguagePythonMIT LicenseMIT

GSON

GSON is a simple python project built to Visualize JSON data as plots, pies and bars.

JSON format to use:

For Plot:

{
  "p1": {
    "x": [1, 2, 3, 4],
    "y": [2, 4, 3, 4]
  },

  "p2": {
    "x": [1, 2, 3, 4],
    "y": [1, 6, 7, 9]
  },

  "p3": {
    "x": [1, 2, 3, 4],
    "y": [2, 6, 23, 9]
  }

  "..."
}

For Pie & Bars:

{
  "p1": 4,

  "p2": 10,

  "p3": 40,

  "..."
}

Note: You can put your data in a sub directory in the JSON file.


Functions used in GSON:

Opening JSON file:

...
    with open(src) as f:
        data = json.load(f)

    if subset_key:
        if subset_key in data:
            data = {subset_key: data[subset_key]}
        else:
            raise KeyError(f"The specified subset key '{subset_key}' does not exist in the JSON data.")
...

Use data for Plot:

...
    for i, inner_dict in enumerate(data.values()):
        values_list = list(inner_dict.values())
        x_values = values_list[0]
        y_values = values_list[1]
...

Use data for Pie & Bars:

...
    keys = list(data.keys())
    values = list(data.values())
...

Call Functions

For Plot:

visualize_plot(src: str, colors: list, linestyle: str = 'solid', linewidth: int = 1, title: str = 'Graph', x_axis: str = 'x-axis', y_axis: str = 'y-axis', subset_key: str = None)

For Pie:

visualize_pie(src: str, colors: list, title: str = 'Pie', subset_key: str = None)

For Bars:

visualize_bar(src: str, colors: list, title: str = 'Bars', x_axis: str = 'x-axis', y_axis: str = 'y-axis', subset_key: str = None)

Images:

2 3 1

Feel free to contribute to the project