Skip to content

Plot with matplotlib

Plot with Matplotlib

Below is an example of how to use the duqtools api to plot data with matplotlib.

import matplotlib.pyplot as plt

from duqtools.api import ImasHandle

handle = ImasHandle.from_string('g2vazizi/jet/94875/8000')

x_var = 'rho_tor_norm'
y_var = 'zeff'
time_var = 'time'

dataset = handle.get_variables(variables=(x_var, y_var, time_var))

fig = dataset.plot.scatter(x_var, y_var, hue='time', marker='.')

Source code

The code below shows how to make a plot with matplotlib for multiple datasets.

For a more advanced example of how to concatenate data, check out the example notebooks.

import matplotlib.pyplot as plt
import pandas as pd
import xarray as xr

from duqtools.api import ImasHandle, standardize_grid_and_time

runs = 8000, 8001, 8002

x_var = 'rho_tor_norm'
y_var = 't_i_ave'
time_var = 'time'

ds_list = []

for run in runs:
    handle = ImasHandle(user='g2vazizi', db='jet', shot='94875', run=run)

    ds = handle.get_variables(variables=(x_var, y_var, time_var))

ds_list = standardize_grid_and_time(ds_list, grid_var=x_var, time_var=time_var)

dataset = xr.concat(ds_list, pd.Index(runs, name='run'))

fig = dataset.plot.scatter(x_var, y_var, hue='time', col='run', marker='.')

Source code