-
Notifications
You must be signed in to change notification settings - Fork 1
/
line_style.py
167 lines (133 loc) · 5.69 KB
/
line_style.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# -*- coding: utf-8 -*-
"""
# see also
# markerfacecolor
# linewidth or lw
"""
class LineStyle():
"""
dispenses row by row a tuple of row style types to
help make it easy to tell graph lines apart
use instead of mathplot defaults
use:
( this may be out of date see use in graph_smart_plug )
import line_style
self.line_style = line_style.LineStyle()
self.current_style = self.lineStyle.get_next_style() # ( line, color, marker, width )
.....plot( x, y, label= alabel, linestyle = self.current_style[0], color = self.current_style[1],
marker = self.current_style[2] , linewidth = self.current_style[3] )
or after the get_next_style you can access the instant values
self.line_style.marker_style ........
self.line_style.reset() # for a new set
!!consider changing to named tuple
may be more styles....
matplotlib.lines.Line2D — Matplotlib 3.1.1 documentation
https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_linestyle
markers = {'.': 'point', ',': 'pixel', 'o': 'circle', 'v': 'triangle_down', '^': 'triangle_up', '<':
'triangle_left', '>': 'triangle_right', '1': 'tri_down', '2': 'tri_up', '3': 'tri_left', '4': 'tri_right',
'8': 'octagon', 's': 'square', 'p': 'pentagon', '*': 'star', 'h': 'hexagon1', 'H': 'hexagon2', '+': 'plus',
'x': 'x', 'D': 'diamond', 'd': 'thin_diamond', '|': 'vline', '_': 'hline', 'P': 'plus_filled', 'X': 'x_filled', 0:
'tickleft', 1: 'tickright', 2: 'tickup', 3: 'tickdown', 4: 'caretleft', 5: 'caretright', 6: 'caretup', 7: 'caretdown',
8: 'caretleftbase', 9: 'caretrightbase', 10: 'caretupbase', 11: 'caretdownbase', 'None': 'nothing', None: 'nothing',
' ': 'nothing', '': 'nothing'}¶
"""
# -----------------------------------------------
def __init__(self ):
"""
think we want lists to be relatively prime for longest cycle time
"""
self.lines = [ '-', '--', ':' ] # "-." "_" total of 4 ??
self.line_ix = 0
self.max_line = len( self.lines )
self.colors = [ 'red', 'blue', 'cyan', 'green', 'black' ] # want dark colors yellow and orange are light
self.color_ix = 0
self.max_color = len( self.colors )
self.markers = [ 'o', 'x', '+', '*', 'h', 's', "d", "2" ] # "1" ......23 "4"
self.marker_ix = 0
self.max_marker = len( self.markers )
self.widths = [ 1, 2, 3, 4 ] # "1" ......23 "4"
self.max_width = len( self.widths )
# setup, need get_next_style before use
self.linestyle = None
self.colorstyle = None
self.markerstyle = None
self.widthstyle = None
# *>url https://stackoverflow.com/questions/8409095/matplotlib-set-markers-for-individual-points-on-a-line
self.reset()
# -----------------------------------------------
def reset( self, ):
"""
reset for reuse from beginning
need to get next before valid
"""
self.marker_ix = -1
self.color_ix = -1
self.line_ix = -1
self.width_ix = -1
# -----------------------------------------------
def _getNextWidth_( self, ):
"""
inside class use only,
get next line style
"""
self.width_ix += 1
if self.width_ix >= self.max_width:
self.width_ix = 0
self.widthstyle = self.widths[ self.width_ix ]
return self.widthstyle
# -----------------------------------------------
def _getNextLine_( self, ):
"""
inside class use only,
get next line style
"""
self.line_ix += 1
if self.line_ix >= self.max_line:
self.line_ix = 0
self.linestyle = self.lines[ self.line_ix ]
return self.linestyle
# -----------------------------------------------
def _getNextColor_( self, ):
"""
inside class use only,
get next color style
"""
self.color_ix += 1
if self.color_ix >= self.max_color:
self.color_ix = 0
self.colorstyle = self.colors[ self.color_ix ]
return self.colorstyle
# -----------------------------------------------
def _getNextMarker_( self, ):
"""
inside class use only,
get next marker style
"""
self.marker_ix += 1
if self.marker_ix >= self.max_marker:
self.marker_ix = 0
self.markerstyle = self.markers[ self.marker_ix ]
return self.markerstyle
# -----------------------------------------------
def get_next_style( self, ):
"""
get the next tuple: ( line, color, marker )
return tuple see below !! change to named tuple ??
can use the returned or perhaps clear the instance var like .markerstyle
a_linestyle, a_colorstyle, a_markerstyle, a_widthstyle = line_style.get_next_style()
or
line_style.get_next_style()
a_linestyle = line_style.linestyle
a_color = line_style.colorstyle
a_widthstyle
"""
return ( self._getNextLine_() , self._getNextColor_(), self._getNextMarker_(), self._getNextWidth_() )
# =========================== put a test ===================
# ------------------------------------------------
if __name__ == '__main__':
"""
run the application as an object
"""
test = LineStyle()
for ix in range(0,20 ):
print(test.get_next_style())