.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_funcs.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_plot_funcs.py: Function1D object ================= This example shows how to use the Function1D object to analyze and plot results. .. GENERATED FROM PYTHON SOURCE LINES 8-43 .. image:: /gallery/images/sphx_glr_plot_funcs_001.png :alt: plot funcs :class: sphx-glr-single-img .. code-block:: default import numpy as np import matplotlib.pyplot as plt from abipy.abilab import Function1D # Build mesh [0, 2pi] with 100 points. mesh = np.linspace(0, 2*np.pi, num=100) # Compute sine function. sine = Function1D.from_func(np.sin, mesh) # Call matplotlib to plot data. fig = plt.figure() ax = fig.add_subplot(1, 1, 1) # Plot sine. sine.plot_ax(ax, label="sin(x)") # Spline sine on the coarse mesh sx, and plot the data. sx = np.linspace(0, 2*np.pi, num=25) splsine = sine.spline(sx) plt.plot(sx, splsine, "ro", label="splined sine") # Compute the 1-st and 2-nd order derivatives # with finite differences (5-point stencil). for order in [1,2]: der = sine.finite_diff(order=order) der.plot_ax(ax, label="D sin(x) %d" % order) # Integrate the sine function and plot the results. (1 - sine.integral()).plot_ax(ax, marker=".", label=r"$1 - \int\,\sin(x)\,dx$") plt.legend(loc="best") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.101 seconds) .. _sphx_glr_download_gallery_plot_funcs.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/abinit/abipy/gh-pages?filepath=notebooks/gallery/plot_funcs.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_funcs.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_funcs.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_