{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# 2D Scatter\n\nScatter data in two dimensions.\n\nThe x-axis and y-axis define the coordinates of the scattered points.\n\n.. code::\n\n @NX_class = \"NXroot\"\n @default = \"scan1\"\n scan1:\n @NX_class = \"NXentry\"\n @default = \"data\"\n data:\n @NX_class = \"NXdata\"\n @x_indices = [0]\n @y_indices = [0]\n @signal = \"z\"\n x: NX_FLOAT64[500]\n y: NX_FLOAT64[500]\n z: NX_FLOAT64[500]\n\nExplanation:\n\n1. ``@axes`` is omitted since default axes are not applicable.\n\n2. ``z`` is the default signal to be plotted versus ``x`` and ``y``.\n\n3. Each data point in ``z`` has a coordinate in ``x`` and ``y``.\n\nNote that the NXdata structure does **not** describe how the data needs to\nbe plotted. In this example we create a 2D scatter plot in the XY-plane.\nBut the data could also be plotted as a function of ``x`` or ``y`` in a\n`sphx_glr_classes_base_classes_data_plot_curve.py` plot. When defining\n``@axes=\"x\"`` the curve plot would be the most likely intention of the data\npublisher but it is up to the reader to decide how to plot the data.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Data\nimport numpy as np\n\nrstate = np.random.RandomState(42)\nx = rstate.uniform(-3, 3, 500)\ny = rstate.uniform(-3, 3, 500)\nz = (1 - x / 2 + x**5 + y**3) * np.exp(-(x**2) - y**2)\n\n# Plot\nimport matplotlib.pyplot as plt # noqa E402\n\nplt.style.use(\"_mpl-gallery-nogrid\")\n\nfig, ax = plt.subplots()\nax.scatter(x, y, c=z, s=50, alpha=0.7)\n\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.16" } }, "nbformat": 4, "nbformat_minor": 0 }