@@ -39,24 +39,31 @@ def __init__(
39
39
rangex : Optional [list ] = None ,
40
40
rangey : Optional [list ] = None ,
41
41
line_color : tuple = (0 , 255 , 0 ),
42
- ticksx : list = None ,
43
- ticksy : list = None ,
42
+ ticksx : list = (0 , 10 , 30 , 50 , 70 , 90 ),
43
+ ticksy : list = (0 , 10 , 30 , 50 , 70 , 90 ),
44
+ tick_pos : bool = False ,
45
+ fill : bool = False ,
44
46
) -> None :
45
47
"""
46
48
47
49
:param Plot plot: Plot object for the scatter to be drawn
48
50
:param list x: x points coordinates
49
51
:param list y: y points coordinates
50
- :param list|None rangex: x range limits. Defaults to None
52
+ :param list|None rangex: x range limits. Defaults to Nonem
51
53
:param list|None rangey: y range limits. Defaults to None
52
54
:param int|None line_color: line color. Defaults to None
53
55
:param list ticksx: X axis ticks values
54
56
:param list ticksy: Y axis ticks values
57
+ :param bool tick_pos: indicates ticks position. True for below the axes.
58
+ Defaults to ``False``
59
+ :param bool fill: enable the filling of the plot. Defaults to ``False``
55
60
56
61
"""
57
62
self .points = []
58
- self .ticksx = ticksx
59
- self .ticksy = ticksy
63
+ self .ticksx = tuple (ticksx )
64
+ self .ticksy = tuple (ticksy )
65
+
66
+ self ._pointer_index = plot ._pointer_index
60
67
61
68
self ._line_color = set_color (
62
69
plot ._display ,
@@ -67,26 +74,72 @@ def __init__(
67
74
)
68
75
plot ._pointer_index += 1
69
76
70
- max_x = max (x )
71
- min_x = min (x )
72
- max_y = max (y )
73
- min_y = min (y )
77
+ if tick_pos :
78
+ self ._tickposx = plot ._tickheightx
79
+ self ._tickposy = plot ._tickheighty
80
+ else :
81
+ self ._tickposx = 0
82
+ self ._tickposy = 0
74
83
75
- if rangex is None :
76
- self .xmin = min_x - (abs (max_x - min_x ) / 10 )
77
- self .xmax = max_x + (abs (max_x - min_x ) / 10 )
84
+ self .xmin = rangex [0 ]
85
+ self .xmax = rangex [1 ]
86
+ self .ymin = rangey [0 ]
87
+ self .ymax = rangey [1 ]
78
88
79
- else :
80
- self .xmin = min (rangex )
81
- self .xmax = max (rangex )
89
+ self .draw_points (plot , x , y , fill )
90
+ if plot ._showticks :
91
+ if plot ._loggingfirst :
92
+ plot ._loggingfirst = False
93
+ self ._draw_ticks (plot )
94
+ plot ._showticks = False
82
95
83
- if rangey is None :
84
- self .ymin = min_y - (abs (max_y - min_y ) / 10 )
85
- self .ymax = max_y + (abs (max_y - min_y ) / 10 )
86
- else :
87
- self .ymin = min (rangey )
88
- self .ymax = max (rangey )
96
+ def _plot_line (self , plot , index , xnorm , ynorm ):
97
+ plot ._display .line (
98
+ xnorm [index ],
99
+ ynorm [index ],
100
+ xnorm [index + 1 ],
101
+ ynorm [index + 1 ],
102
+ self ._line_color ,
103
+ )
89
104
105
+ def draw_points (self , plot : PLOT , x : list , y : list , fill : bool = False ) -> None :
106
+ """
107
+ Draws points in the plot
108
+ :param Plot plot: plot object provided
109
+ :param list x: list of x values
110
+ :param list y: list of y values
111
+ :param bool fill: parameter to fill the plot graphic. Defaults to False
112
+ :return: None
113
+ """
114
+ self .clear_plot (plot )
115
+ # if self._limits:
116
+ # self._draw_limit_lines(plot)
117
+ self .draw_new_lines (plot , x , y , fill )
118
+
119
+ @staticmethod
120
+ def clear_plot (plot ) -> None :
121
+ """
122
+ Clears the plot area
123
+ """
124
+
125
+ plot ._display .rect (
126
+ plot ._newxmin + 1 + plot ._tickheightx ,
127
+ plot ._newymax + 1 ,
128
+ plot ._buff_width - 2 - 2 * plot .padding - plot ._tickheightx ,
129
+ plot ._buff_height - 2 - 2 * plot .padding - plot ._tickheighty ,
130
+ plot ._background_color ,
131
+ True ,
132
+ )
133
+
134
+ def draw_new_lines (self , plot : PLOT , x : list , y : list , fill : bool = False ) -> None :
135
+ """
136
+ Draw the plot lines
137
+ :param Plot plot: plot object provided
138
+ :param list x: list of x values
139
+ :param list y: list of y values
140
+ :param bool fill: parameter to fill the plot graphic. Defaults to False
141
+ :return: None
142
+ """
90
143
xnorm = tuple (
91
144
[
92
145
int (
@@ -108,31 +161,82 @@ def __init__(
108
161
]
109
162
)
110
163
111
- for index , _ in enumerate (xnorm ):
112
- if index + 1 >= len (xnorm ):
113
- break
114
- if y [index ] >= self .ymax :
115
- continue
164
+ if len (x ) == 1 :
165
+ plot ._display .pixel (xnorm [0 ], ynorm [0 ], self ._line_color )
166
+ else :
167
+ for index , _ in enumerate (xnorm ):
168
+ if index + 1 >= len (xnorm ):
169
+ break
170
+ if y [index ] >= self .ymax :
171
+ continue
172
+
173
+ self ._plot_line (plot , index , xnorm , ynorm )
174
+
175
+ if fill :
176
+ for index , _ in enumerate (xnorm ):
177
+ plot ._display .line (
178
+ xnorm [index ],
179
+ ynorm [index ],
180
+ xnorm [index ],
181
+ plot ._newymin ,
182
+ self ._line_color ,
183
+ )
116
184
117
- self ._draw_plotline (plot , index , xnorm , ynorm )
185
+ def _draw_ticks (self , plot ) -> None :
186
+ """
187
+ Draw ticks in the plot area
118
188
119
- if plot ._showticks :
120
- if plot ._cartesianfirst :
121
- plot ._draw_ticks (x , y , self .ticksx , self .ticksy )
122
- plot ._cartesianfirst = False
123
- plot ._showticks = False
189
+ """
124
190
125
- def _plot_line (self , plot , index , xnorm , ynorm ):
126
- plot ._display .line (
127
- xnorm [index ],
128
- ynorm [index ],
129
- xnorm [index + 1 ],
130
- ynorm [index + 1 ],
131
- self ._line_color ,
191
+ ticksxnorm = tuple (
192
+ [
193
+ int (
194
+ plot .transform (
195
+ self .xmin , self .xmax , plot ._newxmin , plot ._newxmax , _
196
+ )
197
+ )
198
+ for _ in self .ticksx
199
+ ]
200
+ )
201
+ ticksynorm = tuple (
202
+ [
203
+ int (
204
+ plot .transform (
205
+ self .ymin , self .ymax , plot ._newymin , plot ._newymax , _
206
+ )
207
+ )
208
+ for _ in self .ticksy
209
+ ]
132
210
)
133
211
134
- def update (self , plot ):
135
- """
136
- Update the plot with new data
137
- """
138
- plot ._display .fill (0 )
212
+ for i , tick in enumerate (ticksxnorm ):
213
+ plot ._display .line (
214
+ tick ,
215
+ plot ._newymin ,
216
+ tick ,
217
+ plot ._newymin - plot ._tickheightx ,
218
+ plot ._tickcolor ,
219
+ )
220
+ if plot ._showtext :
221
+ plot .show_text (
222
+ "{:.{}f}" .format (self .ticksx [i ], plot ._decimal_points ),
223
+ tick ,
224
+ plot ._newymin ,
225
+ ax = "x" ,
226
+ )
227
+
228
+ for i , tick in enumerate (ticksynorm ):
229
+ plot ._display .line (
230
+ plot ._newxmin ,
231
+ tick ,
232
+ plot ._newxmin + plot ._tickheighty ,
233
+ tick ,
234
+ plot ._tickcolor ,
235
+ )
236
+ if plot ._showtext :
237
+ plot .show_text (
238
+ "{:.{}f}" .format (self .ticksy [i ], plot ._decimal_points ),
239
+ plot ._newxmin ,
240
+ tick ,
241
+ ax = "y" ,
242
+ )
0 commit comments