.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "school-tutorials/trilmax-2025/3_Vampire_link/plot_1_spins_2d.py" .. 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_school-tutorials_trilmax-2025_3_Vampire_link_plot_1_spins_2d.py: Spin-plotting routine (2D) ************************** Here you will find a pre-defined function that can plot the set of spin directions from vampire's output file as a 2D plot. Definition of the plotting function =================================== Execute the cell below to have the function defined .. GENERATED FROM PYTHON SOURCE LINES 13-98 .. code-block:: Python import numpy as np from tqdm import tqdm import matplotlib from mpl_toolkits.axes_grid1 import make_axes_locatable import matplotlib.pyplot as plt def plot_spins( filename, scale=1.0, color_mode="z", color_projection=None, colormap="bwr", vmin=None, vmax=None, xrange=None, yrange=None, zrange=None, ): # Load data data = np.loadtxt(filename, skiprows=1) # Make a cut if needded if xrange is not None: data = data[xrange[0] <= data[:, 0]] data = data[data[:, 0] <= xrange[1]] if yrange is not None: data = data[yrange[0] <= data[:, 1]] data = data[data[:, 1] <= yrange[1]] if zrange is not None: data = data[zrange[0] <= data[:, 2]] data = data[data[:, 2] <= zrange[1]] print(f"Plotting {data.shape[0]} spins after the real-space cut") # Compute color values if color_mode == "z": color_projection = [0.0, 0.0, 1.0] elif color_mode == "y": color_projection = [0.0, 1.0, 0.0] elif color_mode == "x": color_projection = [1.0, 0.0, 0.0] elif color_mode == "projection": if color_projection is None: raise ValueError( f"Expected vector for color_projection, got '{color_projection}'" ) else: raise ValueError( f"Expected 'z', 'y', 'x' or 'projection' for color_mode, got '{color_mode}'" ) color_projection = color_projection / np.linalg.norm(color_projection) colors_values = data[:, 3:] @ color_projection # Get the normalizer for color values if vmin is None: vmin = colors_values.min() if vmax is None: vmax = colors_values.max() # Plot all vectors fig, ax = plt.subplots() im = ax.scatter( x=data[:, 0], y=data[:, 1], s=2 * scale, c=colors_values, cmap=colormap, vmin=vmin, vmax=vmax, ) divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) fig.colorbar(im, cax=cax) print("All spins are processed, starting to show the plot ...") # Show the plot fig.show() .. GENERATED FROM PYTHON SOURCE LINES 99-152 Explanation for the parameters ============================== You have to provide one parameter * filename : str Name of the file with spin positions and directions. Other parameters are optional. They control the appearance of the plot: * scale : float, default 1.0 This parameter controls the scale of the spin vectors length, play with this value for better-looking result. Increase to make spin vectors appear longer. * color_mode : str, default "z" What value to use for coloring of the spins. Supported: * "z" - use z components * "y" - use y components * "x" - use x components * "projection" - use projection along ``color_projection``. * color_projection : (3,) array-like Direction for the spin projection to use for coloring. Used if ``color_mode = "projection"``. * colormap : str, default "bwr" Any colormap supported by matplotlib. See https://matplotlib.org/stable/users/explain/colors/colormaps.html for supported names. * vmin : float, optional min value for color value normalization. * vmax : float, optional max value for color value normalization. * xrange : tuple of 2 float Specifies the real-space range on the graph that is plotted. Use it to cut the regions that you want to plot. * yrange : tuple of 2 float Specifies the real-space range on the graph that is plotted. Use it to cut the regions that you want to plot. * zrange : tuple of 2 float Specifies the real-space range on the graph that is plotted. Use it to cut the regions that you want to plot. Plot with all values set to defaults. .. GENERATED FROM PYTHON SOURCE LINES 152-154 .. code-block:: Python plot_spins("spins-00000020.txt") .. image-sg:: /school-tutorials/trilmax-2025/3_Vampire_link/images/sphx_glr_plot_1_spins_2d_001.png :alt: plot 1 spins 2d :srcset: /school-tutorials/trilmax-2025/3_Vampire_link/images/sphx_glr_plot_1_spins_2d_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Plotting 12108 spins after the real-space cut All spins are processed, starting to show the plot ... .. GENERATED FROM PYTHON SOURCE LINES 155-156 Plot a real-space cut. .. GENERATED FROM PYTHON SOURCE LINES 156-158 .. code-block:: Python plot_spins("spins-00000020.txt", xrange=(-20, 20), yrange=(-20, 20), scale=10) .. image-sg:: /school-tutorials/trilmax-2025/3_Vampire_link/images/sphx_glr_plot_1_spins_2d_002.png :alt: plot 1 spins 2d :srcset: /school-tutorials/trilmax-2025/3_Vampire_link/images/sphx_glr_plot_1_spins_2d_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Plotting 71 spins after the real-space cut All spins are processed, starting to show the plot ... .. GENERATED FROM PYTHON SOURCE LINES 159-160 Plot with coloring according to the value of s_y .. GENERATED FROM PYTHON SOURCE LINES 160-169 .. code-block:: Python plot_spins( "spins-00000020.txt", xrange=(-20, 20), yrange=(-20, 20), scale=10, color_mode="y", ) .. image-sg:: /school-tutorials/trilmax-2025/3_Vampire_link/images/sphx_glr_plot_1_spins_2d_003.png :alt: plot 1 spins 2d :srcset: /school-tutorials/trilmax-2025/3_Vampire_link/images/sphx_glr_plot_1_spins_2d_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Plotting 71 spins after the real-space cut All spins are processed, starting to show the plot ... .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.748 seconds) .. _sphx_glr_download_school-tutorials_trilmax-2025_3_Vampire_link_plot_1_spins_2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_1_spins_2d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_1_spins_2d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_1_spins_2d.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_