Skip to content

Instantly share code, notes, and snippets.

@aug2uag
Created December 28, 2021 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aug2uag/6bc59a45d2526577f8d379c749582911 to your computer and use it in GitHub Desktop.
Save aug2uag/6bc59a45d2526577f8d379c749582911 to your computer and use it in GitHub Desktop.
double y-axes plot
# Import Library
import numpy as np
import matplotlib.pyplot as plt
# Define Data
x = np.arange(0, 15, 0.2)
data_1 = np.sin(x)
data_2 = np.cos(x)
# Create Plot
fig, ax1 = plt.subplots()
ax1.set_xlabel('X-axis')
ax1.set_ylabel('Y1-axis', color = 'red')
ax1.plot(x, data_1, color = 'red')
ax1.tick_params(axis ='y', labelcolor = 'red')
# Adding Twin Axes
ax2 = ax1.twinx()
ax2.set_ylabel('Y2-axis', color = 'blue')
ax2.plot(x, data_2, color = 'blue')
ax2.tick_params(axis ='y', labelcolor = 'blue')
# Show plot
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment