{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Secondary Y-Axis Plotting\n\nThis example shows how to plot on the secondary y-axis\nusing Matplotlib functionality. The secondary_y functionality has been removed from ACT.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nfrom arm_test_data import DATASETS\n\nimport act\n\n# Read in the data from a MET file\nfilename_met = DATASETS.fetch('sgpmetE13.b1.20190101.000000.cdf')\nds = act.io.arm.read_arm_netcdf(filename_met)\n\n# Plot temperature and relative humidity with RH on the right axis\ndisplay = act.plotting.TimeSeriesDisplay(ds, figsize=(10, 6))\n\n# Plot the data and make the y-axes color match the lines\ndisplay.plot('temp_mean', match_line_label_color=True)\ndisplay.day_night_background()\n\n# Get the secondary y-axes and plot the RH on it\nax2 = display.axes[0].twinx()\nax2.plot(ds['time'], ds['rh_mean'], color='orange')\n\n# Then the axes can be updated and modified through the normal matplotlib calls.\ndisplay.axes[0].set_yticks([-5, 0, 5])\ndisplay.axes[0].set_yticklabels([\"That's cold\", \"Freezing\", \"Above Freezing\"])\n\n# Secondary y-axis will use the ax2 axes\nax2.set_yticks([65, 75, 85])\nax2.set_yticklabels(['Not as humid', 'Slightly Humid', 'Humid'])\nax2.set_ylabel('Relative Humidity (%)', color='orange')\n\nplt.tight_layout()\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.14.3" } }, "nbformat": 4, "nbformat_minor": 0 }