PYTHON

matplotlib

Date Published:
Last Modified:

Two Y-Axis Example

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 10, 0.1)
y1 = x**2
y2 = np.sin(x)

fig, ax1 = plt.subplots()

ax2 = ax1.twinx()

ax1.plot(x, y1, color='g')
ax2.plot(x, y2, color='b')

fig.suptitle('Two Y-Axis Example')
ax1.set_xlabel('x')
ax1.set_ylabel('y1')
ax2.set_ylabel('y2')

plt.show()

This will produce the following graph:

Example matplotlib graph using two separate Y-axis.

Example matplotlib graph using two separate Y-axis.


Tags:

    comments powered by Disqus