18
18
ax .set_xlim (- 5 , 5 )
19
19
ax .set_ylim (- 5 , 5 )
20
20
ax .axis ('off' )
21
- COLOR = 'C0'
22
21
23
22
24
- def problems (data : list ,
23
+ def problems (data : str ,
25
24
problem_x : float , problem_y : float ,
26
25
prob_angle_x : float , prob_angle_y : float ):
27
26
"""
28
27
Draw each problem section of the Ishikawa plot.
29
28
30
29
Parameters
31
30
----------
32
- data : indexable object
33
- The input data (can be list or tuple) .
31
+ data : str
32
+ The category name .
34
33
problem_x, problem_y : float, optional
35
34
The `X` and `Y` positions of the problem arrows (`Y` defaults to zero).
36
35
prob_angle_x, prob_angle_y : float, optional
@@ -42,18 +41,18 @@ def problems(data: list,
42
41
None.
43
42
44
43
"""
45
- ax .annotate (str .upper (data [ 0 ] ), xy = (problem_x , problem_y ),
44
+ ax .annotate (str .upper (data ), xy = (problem_x , problem_y ),
46
45
xytext = (prob_angle_x , prob_angle_y ),
47
46
fontsize = '10' ,
48
47
color = 'white' ,
49
48
weight = 'bold' ,
50
49
xycoords = 'data' ,
51
- verticalalignment = " center" ,
52
- horizontalalignment = " center" ,
50
+ verticalalignment = ' center' ,
51
+ horizontalalignment = ' center' ,
53
52
textcoords = 'offset fontsize' ,
54
53
arrowprops = dict (arrowstyle = "->" , facecolor = 'black' ),
55
54
bbox = dict (boxstyle = 'square' ,
56
- facecolor = COLOR ,
55
+ facecolor = 'tab:blue' ,
57
56
pad = 0.8 ))
58
57
59
58
@@ -65,8 +64,8 @@ def causes(data: list, cause_x: float, cause_y: float,
65
64
66
65
Parameters
67
66
----------
68
- data : indexible object
69
- The input data (can be list or tuple) . IndexError is
67
+ data : indexable object
68
+ The input data. IndexError is
70
69
raised if more than six arguments are passed.
71
70
cause_x, cause_y : float
72
71
The `X` and `Y` position of the cause annotations.
@@ -80,7 +79,7 @@ def causes(data: list, cause_x: float, cause_y: float,
80
79
None.
81
80
82
81
"""
83
- for index , cause in enumerate (data [ 1 ] ):
82
+ for index , cause in enumerate (data ):
84
83
# First cause annotation is placed in the middle of the problems arrow
85
84
# and each subsequent cause is plotted above or below it in succession.
86
85
@@ -107,14 +106,14 @@ def causes(data: list, cause_x: float, cause_y: float,
107
106
facecolor = 'black' ))
108
107
109
108
110
- def draw_body (* args ):
109
+ def draw_body (data : dict ):
111
110
"""
112
111
Place each section in its correct place by changing
113
112
the coordinates on each loop.
114
113
115
114
Parameters
116
115
----------
117
- *args : indexable object
116
+ data : dict
118
117
The input data (can be list or tuple). ValueError is
119
118
raised if more than six arguments are passed.
120
119
@@ -127,18 +126,18 @@ def draw_body(*args):
127
126
third_sections = []
128
127
# Resize diagram to automatically scale in response to the number
129
128
# of problems in the input data.
130
- if len (args ) == 1 or len (args ) == 2 :
129
+ if len (data ) == 1 or len (data ) == 2 :
131
130
spine_length = (- 2.1 , 2 )
132
131
head_pos = (2 , 0 )
133
132
tail_pos = ((- 2.8 , 0.8 ), (- 2.8 , - 0.8 ), (- 2.0 , - 0.01 ))
134
133
first_section = [1.6 , 0.8 ]
135
- elif len (args ) == 3 or len (args ) == 4 :
134
+ elif len (data ) == 3 or len (data ) == 4 :
136
135
spine_length = (- 3.1 , 3 )
137
136
head_pos = (3 , 0 )
138
137
tail_pos = ((- 3.8 , 0.8 ), (- 3.8 , - 0.8 ), (- 3.0 , - 0.01 ))
139
138
first_section = [2.6 , 1.8 ]
140
139
second_sections = [- 0.4 , - 1.2 ]
141
- else : # num == 5 or 6
140
+ else : # len(data) == 5 or 6
142
141
spine_length = (- 4.1 , 4 )
143
142
head_pos = (4 , 0 )
144
143
tail_pos = ((- 4.8 , 0.8 ), (- 4.8 , - 0.8 ), (- 4.0 , - 0.01 ))
@@ -147,7 +146,7 @@ def draw_body(*args):
147
146
third_sections = [- 1.5 , - 2.3 ]
148
147
149
148
# Change the coordinates of the annotations on each loop.
150
- for index , problem in enumerate (args ):
149
+ for index , problem in enumerate (data . values () ):
151
150
top_row = True
152
151
cause_arrow_y = 1.7
153
152
if index % 2 != 0 : # Plot problems below the spine.
@@ -168,33 +167,37 @@ def draw_body(*args):
168
167
cause_arrow_x = third_sections [1 ]
169
168
if index > 5 :
170
169
raise ValueError (f'Maximum number of problems is 6, you have entered '
171
- f'{ len (args )} ' )
170
+ f'{ len (data )} ' )
172
171
173
172
# draw main spine
174
- ax .plot (spine_length , [0 , 0 ], color = COLOR , linewidth = 2 )
173
+ ax .plot (spine_length , [0 , 0 ], color = 'tab:blue' , linewidth = 2 )
175
174
# draw fish head
176
175
ax .text (head_pos [0 ] + 0.1 , head_pos [1 ] - 0.05 , 'PROBLEM' , fontsize = 10 ,
177
- color = 'white' )
178
- semicircle = Wedge (head_pos , 1 , 270 , 90 , fc = COLOR )
176
+ weight = 'bold' , color = 'white' )
177
+ semicircle = Wedge (head_pos , 1 , 270 , 90 , fc = 'tab:blue' )
179
178
ax .add_patch (semicircle )
180
179
# draw fishtail
181
- triangle = Polygon (tail_pos , fc = COLOR )
180
+ triangle = Polygon (tail_pos , fc = 'tab:blue' )
182
181
ax .add_patch (triangle )
183
-
184
- problems (problem , prob_arrow_x , 0 , - 12 , y_prob_angle )
182
+ # Pass each category name to the problems function as a string on each loop.
183
+ problems (list (data .keys ())[index ], prob_arrow_x , 0 , - 12 , y_prob_angle )
184
+ # Start the cause function with the first annotation being plotted at
185
+ # the cause_arrow_x, cause_arrow_y coordinates.
185
186
causes (problem , cause_arrow_x , cause_arrow_y , top = top_row )
186
187
187
188
188
189
# Input data
189
- method = ['Method' , ['Time consumption' , 'Cost' , 'Procedures' ,
190
- 'Inefficient process' , 'Sampling' ]]
191
- machine = ['Machine' , ['Faulty equipment' , 'Compatibility' ]]
192
- material = ['Material' , ['Poor-quality input' , 'Raw materials' , 'Supplier' ,
193
- 'Shortage' ]]
194
- measure = ['Measurement' , ['Calibration' , 'Performance' , 'Wrong measurements' ]]
195
- env = ['Environment' , ['Bad conditions' ]]
196
- people = ['People' , ['Lack of training' , 'Managers' , 'Labor shortage' ,
197
- 'Procedures' , 'Sales strategy' ]]
198
-
199
- draw_body (method , machine , material , measure , env , people )
190
+ categories = {
191
+ 'Method' : ['Time consumption' , 'Cost' , 'Procedures' , 'Inefficient process' ,
192
+ 'Sampling' ],
193
+ 'Machine' : ['Faulty equipment' , 'Compatibility' ],
194
+ 'Material' : ['Poor-quality input' , 'Raw materials' , 'Supplier' ,
195
+ 'Shortage' ],
196
+ 'Measurement' : ['Calibration' , 'Performance' , 'Wrong measurements' ],
197
+ 'Environment' : ['Bad conditions' ],
198
+ 'People' : ['Lack of training' , 'Managers' , 'Labor shortage' ,
199
+ 'Procedures' , 'Sales strategy' ]
200
+ }
201
+
202
+ draw_body (categories )
200
203
plt .show ()
0 commit comments