Visualization is crucial to understanding data. This section shows you how to visualise data on the Morph workspace.

Using the visualization function

Morph provides a function for realising simple visualizations in the GUI by creating a file with the extension vg.json. To realise general visualizations such as bar charts and line graphs, the visualization results can be immediately obtained by aggregating the original data.

Treatment

First, open the SQL, Python file containing the aggregated source data for the data you want to visualize.

When you open the file, an icon to start the visualization function appears in the top right-hand corner. Click here.

A file with the extension vg.json is generated on the same level of the directory. Open that file.

A GUI screen for visualization will appear as follows. Set each value and a beautiful graph will be displayed in real time.

Visualization sample

Implement more complex visualizations

If you want to implement more complex visualizations, you can use Python visualization libraries to visualize your data.

Morph recommends using Plotly and Matplotlib for data visualization. Create an object for visualization in these libraries, write a function to return it and execute it, and Morph’s CLI will automatically execute the visualization part. Below are some sample visualizations using Plotly and Matplotlib.

Plotly

import plotly.express as px

import morph
from morph import MorphGlobalContext

@morph.func(
    name="${MORPH_NAME}",
    description="${MORPH_DESCRIPTION}",
)
@morph.load_data("${MORPH_PARENT_NAME}")
def main(context: MorphGlobalContext) -> px.line:
    data = context.data["${MORPH_PARENT_NAME}"]
    # This is where you write your code.
    # The `px.line` function creates a line plot using Plotly Express.
    fig = px.line(data, x="X Axis", y="Y Axis", markers=True)
    fig.update_layout(title="Plotly Plot")
    return fig

Matplotlib

import matplotlib.pyplot as plt

import morph
from morph import MorphGlobalContext

@morph.func(
    name="${MORPH_NAME}",
    description="${MORPH_DESCRIPTION}",
)
@morph.load_data("${MORPH_PARENT_NAME}")
def main(context: MorphGlobalContext) -> plt.Figure:
    data = context.data["${MORPH_PARENT_NAME}"]
    # This is where you write your code.
    # The `plot` function creates a line plot using Matplotlib.
    fig, ax = plt.subplots()
    ax.plot(data["X-Axis"], data["Y-Axis"], marker="o")
    ax.set_title("Matplotlib Plot")
    ax.set_xlabel("X-Axis")
    ax.set_ylabel("Y-Axis")
    return fig

These visualizations output the results of the execution in HTML and PNG. If you want to access these raw data, you can specify the output destination with @morph.func’s output_paths. By specifying @morph.func(output_paths=[‘_private/{name}/{now()}{ext()}’]) in this way, the output is output to _private/{name of function}/{time stamp of execution}{.png, .html}.