<jupyter_start><jupyter_text>Tutorial: Plotting field slice In this tutorial, we demonstrate different ways of setting the FD field values.Firstly, we import the required Field class.<jupyter_code>from finitedifferencefield import Field<jupyter_output><empty_output><jupyter_text>We create a three-dimansional vector field with domain that spans between:- minimum coordinate $c_\text{min} = (1, 1, 1)$ and- maximum coordinate $c_\text{max} = (10, 6, 9)$,with discretisation $d = (1, 1, 1)$.<jupyter_code>cmin = (1, 1, 1)
cmax = (10, 6, 9)
d = (1, 1, 1)
dim = 3<jupyter_output><empty_output><jupyter_text>After all the parameters are specified, we can create a field and give it a name.<jupyter_code>field = Field(cmin, cmax, d, dim=dim, name='fdfield')<jupyter_output><empty_output><jupyter_text>Now, we can set its value to be constant:$$f(x, y, z) = (1, 3, 5)$$<jupyter_code>value = (1, 3, 5)
field.set(value)<jupyter_output><empty_output><jupyter_text>After the field is set, we can plot its slice. Let's plot the slice perpendicular to the $x$ axis at the point $x=5$.<jupyter_code>#PYTEST_VALIDATE_IGNORE_OUTPUT
%matplotlib inline
fig = field.plot_slice('x', 5)
fig.show()<jupyter_output>/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py:397: UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure
  "matplotlib is currently using a non-GUI backend, "<jupyter_text>More precisely, we plot a $y-z$ plane as it is shown on the plot's axes.If this plot is too large, its dimension can be changed by providing an additional argument in the plot_slice function: xsize. A vertical dimension will be set proportionally so that the plot accomodates the finite difference field domain. A default value for xsize is 10.<jupyter_code>#PYTEST_VALIDATE_IGNORE_OUTPUT
fig = field.plot_slice('x', 5, xsize=5)
fig.show()<jupyter_output><empty_output><jupyter_text>Now, we can set the field to be spatially varying, by providing a Python function defining its value:$$f(x, y, z) = (2xy, 2y + x, x + z)$$<jupyter_code>def value(pos):
    x, y, z = pos
    
    fx = 2*x*y
    fy = 2*y + x
    fz = x + z
    
    return (fx, fy, fz)

field.set(value)<jupyter_output><empty_output><jupyter_text>Now, we can plot the 'z' slice at point 5:<jupyter_code>#PYTEST_VALIDATE_IGNORE_OUTPUT
fig = field.plot_slice('x', 3, xsize=7)
fig.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11459640317858637, 'fraction_numerical': 0.018820577164366373, 'mean_word_length': 5.589531680440771, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '318735', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 883, 'n_tokens_neox': 834, 'n_words': 273, 'path': 'docs/ipynb/plotting_field.ipynb', 'repo_name': 'joommf/finitedifferencefield', 'size': '2391'}