파이썬 - 2축 그래프 그리기
import numpy as np
import matplotlib.pyplot as plt
from random import *
x = np.arange(10)
y1 = [random() for _ in x]
y2 = [uniform(1,10) for _ in x]
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
data_y1 = ax1.plot(x, y1, color='b', linestyle='-.', marker='o', label='y1')
data_y2 = ax2.plot(x, y2, color='r', linestyle='--', marker='s', label='y2')
ax1.set_xlabel('x')
ax1.set_ylabel('data_y1')
ax2.set_ylabel('data_y2')
data_y = data_y1+data_y2
labels = [l.get_label() for l in data_y]
plt.legend(data_y, labels, loc=1)
plt.show()
# 각 y축의 범위 설정 방법
ax1.set_ylim(bottom, top)
ax2.set_ylim(bottom, top)
감사합니다~
답글삭제