.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_gallery/mplot3d/plot_2dcollections3d.f90" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_gallery_mplot3d_plot_2dcollections3d.f90: Plot 2D data on 3D plot ======================= Flat data can live on any plane of a 3D axes. This is matplotlib's `2dcollections3d `_. matplotlib has a ``zdir`` argument that picks the plane. fplotlib has none, but the same effect is one array away: :f:subr:`plot3d` and :f:subr:`scatter3d` take all three coordinates, so a curve on the plane ``z = 0`` just gets a third coordinate of zeros, and one on ``y = 0`` gets a second coordinate of zeros. .. GENERATED FROM PYTHON SOURCE LINES 12-22 .. code-block:: Fortran program plot_2dcollections3d use fplotlib, only: dp, figure, legend, plot3d, savefig, scatter3d, view_init, & xlabel, xlim, ylabel, ylim, zlabel, zlim implicit none integer, parameter :: n = 100, m = 20 real(dp), parameter :: pi = 3.14159265358979323846_dp real(dp) :: x(n), y(n), zero(n) real(dp) :: xs(m), ys(m), zs(m), zero_m(m) integer :: i .. GENERATED FROM PYTHON SOURCE LINES 23-25 A sine curve in the x-y plane (z = 0), kept inside the axis limits because fplotlib does not clip 3D data to them. .. GENERATED FROM PYTHON SOURCE LINES 27-35 .. code-block:: Fortran :dedent: 1 do i = 1, n x(i) = real(i - 1, dp)/real(n - 1, dp) end do y = 0.5_dp + 0.5_dp*sin(2.0_dp*pi*x) zero = 0.0_dp call figure(figsize=[8.0_dp, 7.0_dp]) call plot3d(x, y, zero, "C0-", lw=2.0_dp, label="on z = 0") .. GENERATED FROM PYTHON SOURCE LINES 36-38 Scatter points on two other planes: the x-z plane (y = 0) and the y-z plane (x = 0). .. GENERATED FROM PYTHON SOURCE LINES 40-49 .. code-block:: Fortran :dedent: 1 do i = 1, m xs(i) = real(i - 1, dp)/real(m - 1, dp) ys(i) = 0.5_dp + 0.5_dp*sin(4.0_dp*pi*xs(i)) zs(i) = real(i - 1, dp)/real(m - 1, dp) end do zero_m = 0.0_dp call scatter3d(xs, zero_m, ys, s=20.0_dp, c="C1", label="on y = 0") call scatter3d(zero_m, xs, zs, s=20.0_dp, c="C2", marker="^", label="on x = 0") .. GENERATED FROM PYTHON SOURCE LINES 50-51 Axis limits and labels, and a point of view to see all three planes. .. GENERATED FROM PYTHON SOURCE LINES 52-65 .. code-block:: Fortran call xlim(0.0_dp, 1.0_dp) call ylim(0.0_dp, 1.0_dp) call zlim(0.0_dp, 1.0_dp) call xlabel("X") call ylabel("Y") call zlabel("Z") call legend() call view_init(elev=20.0_dp, azim=-35.0_dp) call savefig("2dcollections3d.svg") print *, "wrote 2dcollections3d.svg" end program plot_2dcollections3d .. image-sg:: /auto_gallery/mplot3d/images/sphx_glr_plot_2dcollections3d_001.svg :alt: plot 2dcollections3d :srcset: /auto_gallery/mplot3d/images/sphx_glr_plot_2dcollections3d_001.svg :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none wrote 2dcollections3d.svg .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.028 seconds) .. _sphx_glr_download_auto_gallery_mplot3d_plot_2dcollections3d.f90: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Fortran source code: plot_2dcollections3d.f90 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_2dcollections3d.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_