Altitude Plot with Twin Axes

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 0x7f8b28787250>
../_images/df93f66c7e38a6f72ee4cb9d0acdf7ded4c2d778291c4d3c22ac731aeeddc1fe.png