> For the complete documentation index, see [llms.txt](https://particle-analytics-1.gitbook.io/iota-python-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://particle-analytics-1.gitbook.io/iota-python-api/examples/multi-result-variation-line-single-graph.md).

# Creating Multiple Result Line Variations and Plotting them in a Single Graph

This is an example of a `run(scenario)` script that loads coarse-graining (cg) dataset and gets the multiple profiles of a result along different lines. The data of the profiles is saved into the scenario as a single graph with multiple traces, one per line variation (raw data is also saved into a CSV file). Also, the graph is exported into a interactive HTML file.

```python
'''This scripts loads the cg_dataset of a scenario. For a given timestep, mesh name,result and list of start and end point defined different line, it gets the profiles of the result along each line. The data of the profiles is saved into the scenario as single graph with a trace per line variation. Also, the CSV file with raw data of the profiles is created on disk and the graph is exported into a HTML file'''

import iota

def run(scenario):

    ## Settings for the line profile ##
    mesh_name = 'cg_volume_mesh'                           #Name of the volume mesh with the coarse-graining results

    res_name = 'Velocity'                                     #Name of the result for getting the line profiles
    res_component = 3                                         #Component of the result (X=0, Y=1, Z=2, Magnitude=3)
    res_analysis = 'none'                                     #Name of the analysis of the result


    ListOfStart_points = [[0,-1,0],[0,0,0],[0,1,0]]           #List of Start points [x,y,z] for the line profiles
    ListOfEnd_points = [[0,-1,1.3],[0,0,1.3],[0,1,1.3]]       #List of End points [x,y,z] for the line profiles
    Npoints = 50                                              #Number of points to get for the line profile
    t = '2.5'                                                 #Value of the timestep to get line from.   
    ########################################

    #### Settings for graph saving ######
    Name_graph = 'Profile {} at {}'.format(res_name,t)                  #Name for the graph
    Title_graph = 'Profile {} at {}'.format(res_name,t)                   #Title to shown in the graph
    xtitle = 'Distance (m)'                                               #Title for x-axis 
    ytitle = res_name + '[m/s]'                                           #Tile for y-axis based on result name + units
    graph_file = '{}/graphs/{}'.format(scenario.directory,Name_graph)     #Output name and path for exporting graph

    ########################################     

    cg_dataset = scenario.get_cg_dataset()                            #Get the coarse-graining dataset of the scenario
    cg_data = cg_dataset.data()                                       #Load the data of the coarse-graining dataset
    ListOfTimesteps = cg_data.timesteps()                             #Get the list of time of the steps
    step = ListOfTimesteps.index(t)                                  #Get the step for time t.

    y_data_profiles = []                                             #To store the y-data of the different line profiles 
    legend = []                                                      #To store the names of the trces for the legened
    graph_tags = {"dataset": cg_data.name(), "mesh": mesh_name, "scenario": scenario.name, "result": res_name}

    for Start_point,End_point in zip(ListOfStart_points,ListOfEnd_points):

        x_data , y_data = cg_data.line_variation(step=step, mesh=mesh_name, 
            point_start=iota.Vector3d(Start_point), point_end=iota.Vector3d(End_point), num_points = Npoints, 
                result=res_name, analysis=res_analysis, component=res_component, x_type='dist')  #Get line profile data

        y_data_profiles.append(y_data[0])
        legend.append('{} to {}'.format(Start_point, End_point))          #Append name of the trace for the graph legend]

    graph = scenario.add_graph(name=Name_graph, title=Title_graph, xdata=x_data, ydata=y_data_profiles, 
        xtitle=xtitle, ytitle=ytitle, legend=legend,tags=graph_tags)       #Save the graph data to database (including raw data to csv file)

    graph.export_html(graph_file)                                        #Export the graph into html format
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://particle-analytics-1.gitbook.io/iota-python-api/examples/multi-result-variation-line-single-graph.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
