Skip to content

Instantly share code, notes, and snippets.

@BexTuychiev
Created September 21, 2020 10:45
Show Gist options
  • Select an option

  • Save BexTuychiev/381c28ba23177b3d567fefdfc065e065 to your computer and use it in GitHub Desktop.

Select an option

Save BexTuychiev/381c28ba23177b3d567fefdfc065e065 to your computer and use it in GitHub Desktop.
# Create a figure and an axis
fig, ax = plt.subplots()
# Plot CO2 emissions with a blue line
ax.plot(climate_change['date'], climate_change['co2'], color='blue')
# Specify that we will be using a twin x axis
ax2 = ax.twinx()
ax2.plot(climate_change['date'], climate_change['relative_temp'], color='red')
# Change the color of ticks
ax.tick_params('y', colors='blue') # 'y' because we want to change the y axis
ax2.tick_params('y', colors='red')
ax.set(title='CO2 emmissions and relative temperature by year',
xlabel='Year') # Does not matter which one you pick, ax or ax2
plt.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment