seolpyo-mplchart 0.1.3.1__py3-none-any.whl → 2.0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- seolpyo_mplchart/__init__.py +164 -99
- seolpyo_mplchart/_base.py +117 -0
- seolpyo_mplchart/_chart/__init__.py +137 -0
- seolpyo_mplchart/_chart/_base.py +217 -0
- seolpyo_mplchart/_chart/_cursor/__init__.py +2 -0
- seolpyo_mplchart/_chart/_cursor/_artist.py +217 -0
- seolpyo_mplchart/_chart/_cursor/_cursor.py +165 -0
- seolpyo_mplchart/_chart/_cursor/_info.py +187 -0
- seolpyo_mplchart/_chart/_draw/__init__.py +2 -0
- seolpyo_mplchart/_chart/_draw/_artist.py +50 -0
- seolpyo_mplchart/_chart/_draw/_data.py +314 -0
- seolpyo_mplchart/_chart/_draw/_draw.py +103 -0
- seolpyo_mplchart/_chart/_draw/_lim.py +265 -0
- seolpyo_mplchart/_chart/_slider/__init__.py +1 -0
- seolpyo_mplchart/_chart/_slider/_base.py +268 -0
- seolpyo_mplchart/_chart/_slider/_data.py +105 -0
- seolpyo_mplchart/_chart/_slider/_mouse.py +176 -0
- seolpyo_mplchart/_chart/_slider/_nav.py +204 -0
- seolpyo_mplchart/_chart/test.py +121 -0
- seolpyo_mplchart/_config/__init__.py +3 -0
- seolpyo_mplchart/_config/ax.py +28 -0
- seolpyo_mplchart/_config/candle.py +30 -0
- seolpyo_mplchart/_config/config.py +21 -0
- seolpyo_mplchart/_config/cursor.py +49 -0
- seolpyo_mplchart/_config/figure.py +41 -0
- seolpyo_mplchart/_config/format.py +51 -0
- seolpyo_mplchart/_config/ma.py +15 -0
- seolpyo_mplchart/_config/slider/__init__.py +2 -0
- seolpyo_mplchart/_config/slider/config.py +24 -0
- seolpyo_mplchart/_config/slider/figure.py +20 -0
- seolpyo_mplchart/_config/slider/nav.py +9 -0
- seolpyo_mplchart/_config/unit.py +19 -0
- seolpyo_mplchart/_config/utils.py +67 -0
- seolpyo_mplchart/_config/volume.py +26 -0
- seolpyo_mplchart/_cursor.py +559 -0
- seolpyo_mplchart/_draw.py +634 -0
- seolpyo_mplchart/_slider.py +634 -0
- seolpyo_mplchart/base.py +70 -67
- seolpyo_mplchart/cursor.py +308 -271
- seolpyo_mplchart/draw.py +449 -237
- seolpyo_mplchart/slider.py +451 -396
- seolpyo_mplchart/test.py +173 -24
- seolpyo_mplchart/utils.py +15 -4
- seolpyo_mplchart/xl_to_dict.py +47 -0
- seolpyo_mplchart-2.0.0.3.dist-info/METADATA +710 -0
- seolpyo_mplchart-2.0.0.3.dist-info/RECORD +50 -0
- {seolpyo_mplchart-0.1.3.1.dist-info → seolpyo_mplchart-2.0.0.3.dist-info}/WHEEL +1 -1
- seolpyo_mplchart-0.1.3.1.dist-info/METADATA +0 -49
- seolpyo_mplchart-0.1.3.1.dist-info/RECORD +0 -13
- {seolpyo_mplchart-0.1.3.1.dist-info → seolpyo_mplchart-2.0.0.3.dist-info}/top_level.txt +0 -0
seolpyo_mplchart/base.py
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
from re import search
|
|
2
|
+
|
|
1
3
|
import matplotlib.pyplot as plt
|
|
2
4
|
import matplotlib.style as mplstyle
|
|
3
5
|
from matplotlib.axes import Axes
|
|
4
6
|
from matplotlib.backends.backend_agg import FigureCanvasAgg
|
|
7
|
+
from matplotlib.figure import Figure as Fig
|
|
5
8
|
|
|
6
9
|
|
|
7
|
-
from .utils import
|
|
10
|
+
from .utils import dict_unit, dict_unit_en
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
try: plt.switch_backend('TkAgg')
|
|
@@ -17,95 +20,95 @@ except: pass
|
|
|
17
20
|
mplstyle.use('fast')
|
|
18
21
|
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
def convert_unit(value: float, digit=0, word='원'):
|
|
24
|
+
v = value.__abs__()
|
|
25
|
+
du = dict_unit if search('[가-힣]', word) else dict_unit_en
|
|
26
|
+
for unit, n in du.items():
|
|
27
|
+
if n <= v:
|
|
28
|
+
num = (value / n).__round__(digit)
|
|
29
|
+
if not num % 1: num = int(num)
|
|
30
|
+
return f'{num:,}{unit} {word}'
|
|
31
|
+
value = value.__round__(digit)
|
|
32
|
+
if not value % 1: value = int(value)
|
|
33
|
+
elif value < 10: digit = 2
|
|
34
|
+
text = f'{value:,}{word}'
|
|
35
|
+
return text
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Figure(Fig):
|
|
21
39
|
canvas: FigureCanvasAgg
|
|
22
|
-
unit_price, unit_volume = ('원', '주')
|
|
23
40
|
|
|
24
|
-
|
|
25
|
-
|
|
41
|
+
|
|
42
|
+
class Base:
|
|
43
|
+
figure: Figure
|
|
44
|
+
|
|
45
|
+
figsize = (14, 7)
|
|
46
|
+
ratio_ax_legend, ratio_ax_price, ratio_ax_volume = (2, 18, 5)
|
|
26
47
|
adjust = dict(
|
|
27
48
|
top=0.95, bottom=0.05, left=0.01, right=0.93, # 여백
|
|
28
49
|
wspace=0, hspace=0 # 플롯간 간격
|
|
29
50
|
)
|
|
30
|
-
color_grid = '#d0d0d0'
|
|
31
|
-
color_background = '#fafafa'
|
|
32
51
|
|
|
33
|
-
slider_top = True
|
|
34
52
|
title = 'seolpyo mplchart'
|
|
53
|
+
color_background = '#fafafa'
|
|
54
|
+
gridKwargs = {}
|
|
55
|
+
color_tick, color_tick_label = ('k', 'k')
|
|
56
|
+
|
|
57
|
+
unit_price, unit_volume = ('원', '주')
|
|
35
58
|
|
|
36
59
|
def __init__(self, *args, **kwargs):
|
|
37
60
|
# 기본 툴바 비활성화
|
|
38
61
|
plt.rcParams['toolbar'] = 'None'
|
|
62
|
+
# plt.rcParams['figure.dpi'] = 600
|
|
39
63
|
|
|
40
|
-
self.
|
|
64
|
+
self._get_plot()
|
|
41
65
|
return
|
|
42
66
|
|
|
43
|
-
def
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
58
|
-
ax: list[Axes]
|
|
59
|
-
ax_legend, ax_price, ax_volume, ax_none, ax_slider = ax
|
|
60
|
-
# 사용하지 않는 axes 숨기기
|
|
61
|
-
ax_none.axis('off')
|
|
62
|
-
ax_legend.axis('off')
|
|
63
|
-
|
|
64
|
-
ax_slider.xaxis.set_animated(True)
|
|
65
|
-
ax_slider.yaxis.set_animated(True)
|
|
66
|
-
|
|
67
|
-
ax_price.xaxis.set_animated(True)
|
|
68
|
-
ax_price.yaxis.set_animated(True)
|
|
69
|
-
|
|
70
|
-
ax_volume.xaxis.set_animated(True)
|
|
71
|
-
ax_volume.yaxis.set_animated(True)
|
|
72
|
-
|
|
73
|
-
fig.canvas.manager.set_window_title(f'{self.title}')
|
|
67
|
+
def _get_plot(self):
|
|
68
|
+
self.figure, axes = plt.subplots(
|
|
69
|
+
3, # row 수
|
|
70
|
+
figsize=self.figsize, # 기본 크기
|
|
71
|
+
height_ratios=(self.ratio_ax_legend, self.ratio_ax_price, self.ratio_ax_volume) # row 크기 비율
|
|
72
|
+
)
|
|
73
|
+
axes: list[Axes]
|
|
74
|
+
self.ax_legend, self.ax_price, self.ax_volume = axes
|
|
75
|
+
self.ax_legend.set_label('legend ax')
|
|
76
|
+
self.ax_price.set_label('price ax')
|
|
77
|
+
self.ax_volume.set_label('volume ax')
|
|
78
|
+
|
|
79
|
+
self.figure.canvas.manager.set_window_title(f'{self.title}')
|
|
80
|
+
self.figure.set_facecolor(self.color_background)
|
|
74
81
|
|
|
75
82
|
# 플롯간 간격 제거(Configure subplots)
|
|
76
|
-
|
|
83
|
+
self.figure.subplots_adjust(**self.adjust)
|
|
84
|
+
|
|
85
|
+
self.ax_legend.set_axis_off()
|
|
77
86
|
|
|
78
87
|
# y ticklabel foramt 설정
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
ax_volume.yaxis.set_major_formatter(lambda x, _: convert_unit(x, word=self.unit_volume))
|
|
88
|
+
self.ax_price.yaxis.set_major_formatter(lambda x, _: convert_unit(x, word=self.unit_price, digit=2))
|
|
89
|
+
self.ax_volume.yaxis.set_major_formatter(lambda x, _: convert_unit(x, word=self.unit_volume, digit=2))
|
|
82
90
|
|
|
91
|
+
gridKwargs = {'visible': True, 'linewidth': 0.7, 'color': '#d0d0d0', 'linestyle': '-', 'dashes': (1, 0)}
|
|
92
|
+
gridKwargs.update(self.gridKwargs)
|
|
83
93
|
# 공통 설정
|
|
84
|
-
for
|
|
94
|
+
for ax in (self.ax_price, self.ax_volume):
|
|
95
|
+
ax.xaxis.set_animated(True)
|
|
96
|
+
ax.yaxis.set_animated(True)
|
|
97
|
+
|
|
98
|
+
# x tick 외부 눈금 표시하지 않기
|
|
99
|
+
ax.xaxis.set_ticks_position('none')
|
|
100
|
+
# x tick label 제거
|
|
101
|
+
ax.set_xticklabels([])
|
|
85
102
|
# y tick 우측으로 이동
|
|
86
|
-
|
|
87
|
-
#
|
|
88
|
-
|
|
89
|
-
# grid(구분선, 격자) 그리기
|
|
90
|
-
a.grid(True, color=self.color_grid, linewidth=1)
|
|
91
|
-
# x tick 제거
|
|
92
|
-
a.set_xticklabels([])
|
|
93
|
-
|
|
94
|
-
self.fig, self.canvas = (fig, fig.canvas)
|
|
95
|
-
self.ax_slider, self.ax_legend, self.ax_price, self.ax_volume = (ax_slider, ax_legend, ax_price, ax_volume)
|
|
103
|
+
ax.tick_params(left=False, right=True, labelleft=False, labelright=True, colors=self.color_tick_label)
|
|
104
|
+
# Axes 외곽선 색 변경
|
|
105
|
+
for i in ['top', 'bottom', 'left', 'right']: ax.spines[i].set_color(self.color_tick)
|
|
96
106
|
|
|
97
|
-
|
|
107
|
+
# 차트 영역 배경 색상
|
|
108
|
+
ax.set_facecolor(self.color_background)
|
|
98
109
|
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
# grid(구분선, 격자) 그리기
|
|
111
|
+
# 어째서인지 grid의 zorder 값을 선언해도 1.6을 값으로 한다.
|
|
112
|
+
ax.grid(**gridKwargs)
|
|
101
113
|
return
|
|
102
114
|
|
|
103
|
-
|
|
104
|
-
class Chart(Base):
|
|
105
|
-
pass
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if __name__ == '__main__':
|
|
109
|
-
Base()
|
|
110
|
-
|
|
111
|
-
plt.show()
|