.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/pytplot_demo.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_generated_gallery_pytplot_demo.py: ============ PyTplot Demo ============ Written by Julie Barnum and Elysia Lucas. The purpose of this demo is to show off some of the capabilities of PyTplot. .. GENERATED FROM PYTHON SOURCE LINES 10-14 .. code-block:: default import urllib import pytplot .. GENERATED FROM PYTHON SOURCE LINES 15-22 Loading data into memory ------------------------ The pytplot package comes with a sample IDL tplot save file which will be used for the following tutorial, located in PyTplot Github (https://github.com/MAVENSDC/PyTplot) under pytplot/pytplot/sampledata. This file was generated in IDL, and therefore can be loaded into tplot if you wish to compare the IDL and python versions. Download the test file from the PyTplot Github acct .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: default url = 'https://github.com/MAVENSDC/PyTplot/raw/master/docs/test_data.tplot' urllib.request.urlretrieve(url, "./test_data.tplot") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ('./test_data.tplot', ) .. GENERATED FROM PYTHON SOURCE LINES 27-28 To load this data into pytplot, type in the following command: .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: default pytplot.tplot_restore(r'test_data.tplot') print(pytplot.tplot_names()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0 : SEP_2_ELEC 1 : SEP_1_ION 2 : SEP_2_ION 3 : swia_counts 4 : swia_den 5 : swia_vel 6 : mag 7 : orbit ['SEP_2_ELEC', 'SEP_1_ION', 'SEP_2_ION', 'swia_counts', 'swia_den', 'swia_vel', 'mag', 'orbit'] .. GENERATED FROM PYTHON SOURCE LINES 32-51 Storing data ------------ pytplot works by interacting with global variables (called tplot variables) that contain information necessary for creating one panel (or even one portion of a panel) of a plot, that can be accessed from the main level or within any Python routine. Before anything can be plotted, tplot variables must be loaded into memory. Single line Plot: to store data to plot a single line, the 'y' data will be a single list of data that will correspond to the points that will make up the line. Multi-line Plot: to store data to plot a multi-line plot, the 'y' data will be a list of lists. Each column of the "matrix" created is the data for one line. So if you had a list with four lists in it and three elements in each list [[1,2,3],[4,5,6],[7,8,9],[10,11,12]] three lines with four data points each will be plotted. Spectrogram Plot: to store data to plot for a spectrogram, 'v' data will be a list of bins for the data, and the 'y' data will be a matrix of values with dimensions of the length of "x" time the length of "v" Map Plot: to store data to plot for a latitude/longitude plot, 'x' will contain a list of latitudes and a list of longitudes, for example 'x':[[15,30,45],[30,60,90]], and the 'y' data will be a list of values that correspond to those latitude/longitude points Combining Two Plots: store_data('new_name', ['old_name1', 'old_name2']) to combine multiple existing tplot variables ('old_name1' and 'old_name2') into one new tplot variable ('new_name'). 'new_name' will have all data from the existing tplot variables entered in one new tplot variable. .. GENERATED FROM PYTHON SOURCE LINES 53-58 Pytplot variables ----------------- pytplot.tplot_names() will print the numbers and names of the tplot variables currently in memory. When using any routines that require the name of the tplot variable, the user can use either the name of the variable or the corresponding number. .. GENERATED FROM PYTHON SOURCE LINES 58-61 .. code-block:: default pytplot.tplot_names() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0 : SEP_2_ELEC 1 : SEP_1_ION 2 : SEP_2_ION 3 : swia_counts 4 : swia_den 5 : swia_vel 6 : mag 7 : orbit ['SEP_2_ELEC', 'SEP_1_ION', 'SEP_2_ION', 'swia_counts', 'swia_den', 'swia_vel', 'mag', 'orbit'] .. GENERATED FROM PYTHON SOURCE LINES 62-67 Options ------- pytplot.options('tplot_var', 'option', 'option_value') can be used to change plotting options corresponding to specific tplot variables. All options currently implemented are described in the pytplot documentation, but here are some examples to get you started. .. GENERATED FROM PYTHON SOURCE LINES 67-77 .. code-block:: default # Line Thickness pytplot.options('swia_vel', 'thick', 4) # Y-axis Label pytplot.options('swia_vel', 'ytitle', 'speed (km/s)') # Vertical Plot Bounds pytplot.options('SEP_1_ION', 'yrange', [5, 5000]) # Panel Size pytplot.options(['mag', 'swia_den', 'swia_vel'], 'panel_size', 0.5) .. GENERATED FROM PYTHON SOURCE LINES 78-82 Tplot Options ------------- pytplot.tplot_options('option', 'option_value') can be used to change plotting options for the tplot routine. These control options affect all panels in a plot. .. GENERATED FROM PYTHON SOURCE LINES 82-97 .. code-block:: default # Title pytplot.tplot_options('title', 'All Plots') # Window Size pytplot.tplot_options('wsize', [800, 800]) # Adding a region of interest (ROI) # pytplot will add a ROI (indicated by two vertical red lines, with grey shading in between) # to all plot via specifying the 'roi' option pytplot.tplot_options('roi', ['2016-06-20 11:12:24', '2016-06-20 14:12:00']) # Another option available in tplot_options is to specify the number of seconds with consecutive nan # values allowed before no interpolation should occur pytplot.tplot_options('data_gap', 80) .. GENERATED FROM PYTHON SOURCE LINES 98-101 Displaying data using tplot --------------------------- Single Panel Plot .. GENERATED FROM PYTHON SOURCE LINES 101-106 .. code-block:: default pytplot.tplot('swia_vel') # or, pytplot.tplot(6) # Multiple Panel Plot pytplot.tplot(['swia_counts', 'swia_vel', 'mag']) # or, pytplot.tplot([4,6,7]) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/pytplot/tplot_utilities.py:312: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations map = [(np.array(cm(x))*255).astype(np.int) for x in range(0, cm.N)] /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/pytplot/tplot_utilities.py:312: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations map = [(np.array(cm(x))*255).astype(np.int) for x in range(0, cm.N)] .. GENERATED FROM PYTHON SOURCE LINES 107-112 Interacting with Data Plots --------------------------- There are several ways to interact with the data plots. There is command line interaction that follows the same pattern of functions IDL utilizes. Pytplot additionally has interactivity built into the viewing window in the form of "tools". .. GENERATED FROM PYTHON SOURCE LINES 112-142 .. code-block:: default # Moving forward and backward in time # The Pan tool allows the user to click and drag the mouse on the plot to move along the x- or y-axis. # Zooming in and out # The Box Zoom tool allows the user to click and drag the mouse on the plot to specify # their desired x-axis range. # Show data points # The Hover Tool displays the data of a given point when the user hovers their mouse over the line. # Add crosshairs to plot window # The Crosshairs Tool displays a set of crosshairs that follow the location of the mouse on the plot. # Crosshairs can be modified to be not displayed... pytplot.tplot_options('crosshair', False) pytplot.tplot('swia_counts') # and crosshair names can be modified. pytplot.tplot_options('crosshair', True) # Just re-adding the crosshairs pytplot.options('swia_counts', 'crosshair_x', 'XXX') pytplot.options('swia_counts', 'crosshair_y', 'YYY') pytplot.options('swia_counts', 'crosshair_z', 'ZZZ') pytplot.tplot('swia_counts') # Adding timebars # To place a vertical line at a specific time on all panels: # pytplot.timebar('2016-06-20 01:15:32', thick=3, color='green') will add a vertical black line to all plots # at the time entered. Further settings related to this routine are described in the pytplot documentation. pytplot.timebar('2016-06-20 01:15:32', thick=3, color='green') .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/pytplot/tplot_utilities.py:312: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations map = [(np.array(cm(x))*255).astype(np.int) for x in range(0, cm.N)] /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/pytplot/tplot_utilities.py:312: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations map = [(np.array(cm(x))*255).astype(np.int) for x in range(0, cm.N)] /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/pytplot/tplot_utilities.py:312: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations map = [(np.array(cm(x))*255).astype(np.int) for x in range(0, cm.N)] /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/pytplot/tplot_utilities.py:312: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations map = [(np.array(cm(x))*255).astype(np.int) for x in range(0, cm.N)] .. GENERATED FROM PYTHON SOURCE LINES 143-155 Interacting with spectrogram plots ---------------------------------- pytplot also has the ability to interact directly with spectrograms. If you supply the interactive=True keyword to a pytplot.tplot command, a plot will appear next to the spectrogram that reads out "slices" of the plot when you hover the mouse over it. Additionally, you can set options in pytplot to include 'static_tavg', 'static', and 't_average', which creates a separate plot with the average over a specified time period, creates a separate plot with a single specified time period, and specifies a time period (in seconds, based on the mouse's current location) over which time should be averaged for the window which pops up when 'interactive=true' is specified, respectively. You can also log axes in both the spectrogram plots ('xlog' and 'zlog' options), and the interactive plots ('xlog_interactive' and 'ylog_interactive' options). .. GENERATED FROM PYTHON SOURCE LINES 155-165 .. code-block:: default pytplot.options('swia_counts', 'ylog', 1) # setting to 0 would make the y-axis linear pytplot.options('swia_counts', 'zlog', 1) # setting ot 0 would make the z-axis linear pytplot.options('swia_counts', 'xlog_interactive', True) # Setting to False would make the x-axis linear pytplot.options('swia_counts', 'ylog_interactive', True) # Setting to False would make the y-axis linear pytplot.options('swia_counts', 'static_tavg', ['2016-06-20 12:00:00', '2016-06-20 13:00:00']) pytplot.options('swia_counts', 'static', '2016-06-20 01:00:57') pytplot.options('swia_counts', 't_average', 1200) pytplot.tplot('swia_counts') .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/pytplot/tplot_utilities.py:312: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations map = [(np.array(cm(x))*255).astype(np.int) for x in range(0, cm.N)] /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/pytplot/tplot_utilities.py:312: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations map = [(np.array(cm(x))*255).astype(np.int) for x in range(0, cm.N)] /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/pytplot/AncillaryPlots/spec_slicer.py:150: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations y_values_avgd = y_values_slice.sum(dim='time', keep_attrs=True)/np.float(time_diff) /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/pytplot/AncillaryPlots/spec_slicer.py:150: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations y_values_avgd = y_values_slice.sum(dim='time', keep_attrs=True)/np.float(time_diff) .. GENERATED FROM PYTHON SOURCE LINES 166-171 Saving output ------------- pytplot plots have the ability to be saved via 'Save PNG' option from the plot window, or you can specify that you want to save a plot ahead of time via the 'save_png' option (e.g., pytplot.tplot('swia_counts', save_png = '/path/to/png/PNG.png') .. GENERATED FROM PYTHON SOURCE LINES 173-178 Displaying in bokeh ------------------- pytplot allows you to use bokeh for visualizing data (bokeh is a Python library that allows interactive plots to be visualized via a web browser window), via the 'bokeh' option (e.g., pytplot.tplot('swia_counts', bokeh=True) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 13.554 seconds) .. _sphx_glr_download_generated_gallery_pytplot_demo.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/HeliophysicsPy/gallery/gh-pages?urlpath=lab/tree/notebooks/generated/gallery/pytplot_demo.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pytplot_demo.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pytplot_demo.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_