<jupyter_start><jupyter_text>Plotting: 1D and 2D dataThis notebook show how to visualize 1D and 2d simulation data.<jupyter_code>import osyris
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Plotting 1D data1D and 2D data are loaded in exactly the same way as 3D simulations,by creating a `Dataset` and calling the `load()` method.<jupyter_code>path = "osyrisdata/sod"
data1d = osyris.Dataset(2, scale="cm", path=path).load()
data1d<jupyter_output><empty_output><jupyter_text>Line profileTo plot a simple line profile of density as a function of position,Osyris provides the `plot` function which is analogous to Matplotlib's[plot](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html) function.<jupyter_code>osyris.plot(data1d['amr']['xyz_x'], data1d['hydro']['density'])<jupyter_output><empty_output><jupyter_text>Styling linesBecause the function is based on Matplotlib's implementation,it also supports Matplotlib's styling arguments.For instance, to plot using red marker instead of a solid line,you can do<jupyter_code>osyris.plot(data1d['amr']['xyz_x'], data1d['hydro']['density'],
           marker='o', ls='None', color='red')<jupyter_output><empty_output><jupyter_text>Logarithmic scalesOsyris does provide some convenience arguments in addition to Matplotlib's functionalty.For example, to set a logarithmic scale on the x and y axes, use the `logx` and `logy` arguments<jupyter_code>osyris.plot(data1d['amr']['xyz_x'], data1d['hydro']['density'],
           marker='o', ls='None', logx=True, logy=True)<jupyter_output><empty_output><jupyter_text>Multiple linesIt is also possible to over-plot multiple lines in one go,by supplying more than one array for the `y` values.However, note that to be able to plot the variables on a single axis,they must all have the same unit.<jupyter_code>try:
    osyris.plot(data1d['amr']['xyz_x'],
                data1d['hydro']['density'],
                data1d['hydro']['pressure'])
except Exception as e:
    print(e)<jupyter_output><empty_output><jupyter_text>To be able to show an example, we fake a new density variable.<jupyter_code>data1d['hydro']['new_density'] = data1d['hydro']['density'] * 2
osyris.plot(data1d['amr']['xyz_x'],
            data1d['hydro']['density'],
            data1d['hydro']['new_density'])<jupyter_output><empty_output><jupyter_text>By default, the same x coordinate will be used for both sets of y values.It is however possible to plot on the same axes two variables with different x coordinates.In this case, the two entries must be dicts, and they must contain at least the entries `'x'` and `'y'`.This is useful in the case where one wishes to compare two outputs from different times,which do not contain the same number of mesh cells (and hence cannot have the same x coordinate).<jupyter_code>old1d = osyris.Dataset(1, scale="cm", path=path).load()

osyris.plot({'x': data1d['amr']['xyz_x'], 'y': data1d['hydro']['density']},
            {'x': old1d['amr']['xyz_x'], 'y': old1d['hydro']['density']},
            marker='o', ls='None')<jupyter_output><empty_output><jupyter_text>Subplots / tiled plotsOsyris has no built-in support for subplots (also known as tiled plots).Instead, we leverage Matplotlib's ability to create such layouts.Osyris plots are then inserted into the Matplotlib axes, using the `ax` argument.In the example below, we create four panels and insert various plots.<jupyter_code>fig, ax = plt.subplots(2, 2, figsize=(12, 9))

osyris.plot(data1d['amr']['xyz_x'], data1d['hydro']['density'],
            marker='o', ls='None', ax=ax[0, 0])
osyris.plot(data1d['amr']['xyz_x'], data1d['hydro']['velocity_x'],
            color='green', ax=ax[0, 1])
osyris.plot(data1d['amr']['xyz_x'], data1d['hydro']['pressure'],
            color='red', ax=ax[1, 0])
osyris.plot(data1d['amr']['xyz_x'], data1d['amr']['level'],
            color='black', ls='dotted', ax=ax[1, 1])<jupyter_output><empty_output><jupyter_text>Plotting 2D dataThis section briefly shows how to make images of 2D data with the `map` function.For a full description of all the options available, see [Plotting: spatial maps](plotting_maps.ipynb).<jupyter_code>data2d = osyris.Dataset(2, scale="cm", path="osyrisdata/sedov").load()<jupyter_output><empty_output><jupyter_text>To make an image of the gas density, simply use<jupyter_code>osyris.map({"data": data2d['hydro']["density"], "norm": "log"}, cmap='jet')<jupyter_output><empty_output><jupyter_text>A map of the AMR level is obtained with<jupyter_code>osyris.map({"data": data2d['amr']["level"]})<jupyter_output><empty_output><jupyter_text>The size of the viewport can be adjusted with the `dx` argument:<jupyter_code>osyris.map({"data": data2d['hydro']["density"], "norm": "log"},
             dx=2 * osyris.units('cm'),
             cmap='jet')<jupyter_output><empty_output><jupyter_text>Finally, you can also use an additional layer to overlay velocity vectors<jupyter_code>osyris.map({"data": data2d['hydro']["density"], "norm": "log"},
           {"data": data2d['hydro']["velocity"], "mode": "vec", "color": "black"},
           cmap='jet')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14567996900426192, 'fraction_numerical': 0.012204571871367687, 'mean_word_length': 6.0340599455040875, 'pattern_counts': {'":': 10, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '443408', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1691, 'n_words': 461, 'path': 'docs/plotting_1d_2d.ipynb', 'repo_name': 'matthiasglz/osyris', 'size': '5162'}