반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[matplotlib] legend picking chart sample 본문

Python/matplotlib

[matplotlib] legend picking chart sample

닉의네임 2022. 8. 19. 14:50
반응형

legend picking chart 혹은 TGV (Tejeb) 이라고 함 

legend picking

때잽질을 하려면 보고가 생명인데, 이 때잽질이라는게 말로 나불거려서 때르잽이 되려면 1급 때잽이여야 하고

텍스트로만 보고하기에는 이해하는 놈들이 일본애니 마니아라서 이해하는데 한계가 있고, 변태스러운 2D 마니아들을 위한 맞춤 보고서를 작성해야 하는데 그때를 대비해서 쓸만한 차트를 몇개 알아놓고 신속하게 때르잽질을 한다

 

sample 

import numpy as np
import matplotlib.pyplot as plt


t = np.linspace(0, 1)
y1 = 2 * np.sin(2*np.pi*t)
y2 = 4 * np.sin(2*np.pi*2*t)

fig, ax = plt.subplots()
ax.set_title('Click on legend line to toggle line on/off')
line1, = ax.plot(t, y1, lw=2, label='1 Hz')
line2, = ax.plot(t, y2, lw=2, label='2 Hz')
leg = ax.legend(fancybox=True, shadow=True)

lines = [line1, line2]
lined = {}  # Will map legend lines to original lines.
for legline, origline in zip(leg.get_lines(), lines):
    legline.set_picker(True)  # Enable picking on the legend line.
    lined[legline] = origline


def on_pick(event):
    # On the pick event, find the original line corresponding to the legend
    # proxy line, and toggle its visibility.
    legline = event.artist
    origline = lined[legline]
    visible = not origline.get_visible()
    origline.set_visible(visible)
    # Change the alpha on the line in the legend so we can see what lines
    # have been toggled.
    legline.set_alpha(1.0 if visible else 0.2)
    fig.canvas.draw()

fig.canvas.mpl_connect('pick_event', on_pick)
plt.show()

자.. 수정을 해보잣 

 

nested aggregation 과 array aggregation 을 테스트 했던 실행시간 데이터를 출력해서 복사

t= range(0, 88)
y1= [67.89, 15.56, 12.77, 13.39, 15.69, 13.18, 16.3, 13.92, 16.8, 14.18, 15.05, 28.49, 15.1, 14.96, 12.1, 13.23, 16.92, 13.55, 16.1, 14.2, 15.43, 12.78, 15.55, 12.78, 12.35, 15.06, 14.21, 15.68, 12.33, 14.07, 15.72, 17.83, 14.73, 15.15, 15.25, 17.16, 14.07, 15.78, 13.09, 16.08, 13.68, 16.5, 13.84, 18.75, 15.81, 13.72, 12.31, 16.27, 13.98, 15.77, 13.66, 16.07, 13.2, 19.21, 17.44, 14.59, 13.94, 13.15, 12.61, 15.28, 12.96, 15.59, 12.87, 17.43, 12.83, 13.27, 14.97, 12.9, 15.94, 14.06, 15.8, 15.65, 15.36, 13.38, 15.62, 13.18, 12.86, 14.95, 13.27, 11.63, 14.37, 11.99, 12.27, 15.38, 12.93, 16.86, 16.48, 19.36]
y2= [15.35, 14.86, 15.27, 12.97, 15.53, 12.2, 12.92, 14.8, 20.03, 12.12, 12.04, 11.95, 15.1, 12.89, 12.03, 14.99, 11.97, 16.91, 12.14, 17.73, 12.21, 12.0, 15.77, 11.25, 12.92, 15.79, 13.17, 12.03, 14.78, 12.25, 12.97, 14.99, 13.07, 12.95, 17.98, 12.02, 15.02, 14.98, 17.03, 11.93, 14.83, 12.24, 11.92, 15.8, 13.24, 12.94, 23.85, 16.22, 16.93, 16.87, 12.11, 12.98, 14.77, 13.21, 13.02, 15.07, 13.98, 14.69, 14.26, 15.8, 13.26, 16.76, 13.16, 16.82, 12.18, 11.97, 15.84, 13.17, 16.73, 15.25, 14.7, 12.26, 11.95, 15.83, 12.18, 12.06, 15.72, 16.3, 16.04, 11.93, 12.07, 15.1, 12.89, 11.98, 15.03, 12.96, 15.77, 13.24]

x label, y label 설정 추가

ax.set_ylabel('query 속도(ms)')
ax.set_xlabel('조회수(회)')

한글을 썼으니 폰트 추가 안그럼 한글 깨짐  깨룩

plt.rcParams['font.family'] = 'AppleGothic'

 

 

sample  code 

import numpy as np
import matplotlib.pyplot as plt

#
# t = np.linspace(0, 1)
# y1 = 2 * np.sin(2*np.pi*t)
# y2 = 4 * np.sin(2*np.pi*2*t)

t= range(0, 88)
y1= [67.89, 15.56, 12.77, 13.39, 15.69, 13.18, 16.3, 13.92, 16.8, 14.18, 15.05, 28.49, 15.1, 14.96, 12.1, 13.23, 16.92, 13.55, 16.1, 14.2, 15.43, 12.78, 15.55, 12.78, 12.35, 15.06, 14.21, 15.68, 12.33, 14.07, 15.72, 17.83, 14.73, 15.15, 15.25, 17.16, 14.07, 15.78, 13.09, 16.08, 13.68, 16.5, 13.84, 18.75, 15.81, 13.72, 12.31, 16.27, 13.98, 15.77, 13.66, 16.07, 13.2, 19.21, 17.44, 14.59, 13.94, 13.15, 12.61, 15.28, 12.96, 15.59, 12.87, 17.43, 12.83, 13.27, 14.97, 12.9, 15.94, 14.06, 15.8, 15.65, 15.36, 13.38, 15.62, 13.18, 12.86, 14.95, 13.27, 11.63, 14.37, 11.99, 12.27, 15.38, 12.93, 16.86, 16.48, 19.36]
y2= [15.35, 14.86, 15.27, 12.97, 15.53, 12.2, 12.92, 14.8, 20.03, 12.12, 12.04, 11.95, 15.1, 12.89, 12.03, 14.99, 11.97, 16.91, 12.14, 17.73, 12.21, 12.0, 15.77, 11.25, 12.92, 15.79, 13.17, 12.03, 14.78, 12.25, 12.97, 14.99, 13.07, 12.95, 17.98, 12.02, 15.02, 14.98, 17.03, 11.93, 14.83, 12.24, 11.92, 15.8, 13.24, 12.94, 23.85, 16.22, 16.93, 16.87, 12.11, 12.98, 14.77, 13.21, 13.02, 15.07, 13.98, 14.69, 14.26, 15.8, 13.26, 16.76, 13.16, 16.82, 12.18, 11.97, 15.84, 13.17, 16.73, 15.25, 14.7, 12.26, 11.95, 15.83, 12.18, 12.06, 15.72, 16.3, 16.04, 11.93, 12.07, 15.1, 12.89, 11.98, 15.03, 12.96, 15.77, 13.24]


plt.rcParams['font.family'] = 'AppleGothic'

fig, ax = plt.subplots()
ax.set_title('nested aggs VS array aggs')
line1, = ax.plot(t, y1, lw=2, label='nested')
line2, = ax.plot(t, y2, lw=2, label='array')
leg = ax.legend(fancybox=True, shadow=True)

ax.set_ylabel('query 속도(ms)')
ax.set_xlabel('조회수(회)')

lines = [line1, line2]
lined = {}  # Will map legend lines to original lines.
for legline, origline in zip(leg.get_lines(), lines):
    legline.set_picker(True)  # Enable picking on the legend line.
    lined[legline] = origline


def on_pick(event):
    legline = event.artist
    origline = lined[legline]
    visible = not origline.get_visible()
    origline.set_visible(visible)
    legline.set_alpha(1.0 if visible else 0.2)
    fig.canvas.draw()

fig.canvas.mpl_connect('pick_event', on_pick)
plt.show()
반응형
Comments