Altitude Plot with Twin Axes#

This example demonstrates:

  • plotting a scatter plot with color by another column

  • showing multiple y axis scales

  • adding a colorbar

  • using latex to get subscripts in a label field

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Import example data - flight from NAAMES campaign
naames = pd.read_csv('../lessons/tabular_data/data/naames-mrg01-c130_merge_20151112_R5_thru20151114.csv', skiprows=223)
# Replace nodata values
naames = naames.replace(-999999, np.nan)
# Filter to just one day
naames = naames[naames[' Fractional_Day'] < 317]
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()

fig.set_size_inches(15, 5)

scatter1 = ax1.scatter(naames[' Fractional_Day'], naames[' ALTP'], c=naames[' Methanol_MixingRatio'])

ax2.plot(naames[' Fractional_Day'], naames[' H2O_MixingRatio_LARGE'], color='black')
ax2.set_ylabel('$H_{2}O\:Mixing\:Ratio$')

ax1.set_ylabel('Altitude (km)')

ax1.set_title('$H_{2}O\:and\:Methanol\:by\:Altitude\:over\:Time$')
ax1.set_xlabel('Julian Day')

fig.colorbar(scatter1, ax=ax1, label="Methanol Mixing Ratio", pad=0.08)
<matplotlib.colorbar.Colorbar at 0x15c903b50>
../_images/ed4efcf7c856d28129be54390bd48eb6b8814f090a1aa5492fc1b35ced38a2c3.png