8000 input data as dict, remove color var · matplotlib/matplotlib@ae97baf · GitHub
[go: up one dir, main page]

Skip to content

Commit ae97baf

Browse files
committed
input data as dict, remove color var
1 parent eab74da commit ae97baf

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

galleries/examples/specialty_plots/ishikawa_diagram.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@
1818
ax.set_xlim(-5, 5)
1919
ax.set_ylim(-5, 5)
2020
ax.axis('off')
21-
COLOR = 'C0'
2221

2322

24-
def problems(data: list,
23+
def problems(data: str,
2524
problem_x: float, problem_y: float,
2625
prob_angle_x: float, prob_angle_y: float):
2726
"""
2827
Draw each problem section of the Ishikawa plot.
2928
3029
Parameters
3130
----------
32-
data : indexable object
33-
The input data (can be list or tuple).
31+
data : str
32+
The category name.
3433
problem_x, problem_y : float, optional
3534
The `X` and `Y` positions of the problem arrows (`Y` defaults to zero).
3635
prob_angle_x, prob_angle_y : float, optional
@@ -42,18 +41,18 @@ def problems(data: list,
4241
None.
4342
4443
"""
45-
ax.annotate(str.upper(data[0]), xy=(problem_x, problem_y),
44+
ax.annotate(str.upper(data), xy=(problem_x, problem_y),
4645
xytext=(prob_angle_x, prob_angle_y),
4746
fontsize='10',
4847
color='white',
4948
weight='bold',
5049
xycoords='data',
51-
verticalalignment="center",
52-
horizontalalignment="center",
50+
verticalalignment='center',
51+
horizontalalignment='center',
5352
textcoords='offset fontsize',
5453
arrowprops=dict(arrowstyle="->", facecolor='black'),
5554
bbox=dict(boxstyle='square',
56-
facecolor=COLOR,
55+
facecolor='tab:blue',
5756
pad=0.8))
5857

5958

@@ -65,8 +64,8 @@ def causes(data: list, cause_x: float, cause_y: float,
6564
6665
Parameters
6766
----------
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
7069
raised if more than six arguments are passed.
7170
cause_x, cause_y : float
7271
The `X` and `Y` position of the cause annotations.
@@ -80,7 +79,7 @@ def causes(data: list, cause_x: float, cause_y: float,
8079
None.
8180
8281
"""
83-
for index, cause in enumerate(data[1]):
82+
for index, cause in enumerate(data):
8483
# First cause annotation is placed in the middle of the problems arrow
8584
# and each subsequent cause is plotted above or below it in succession.
8685

@@ -107,14 +106,14 @@ def causes(data: list, cause_x: float, cause_y: float,
107106
facecolor='black'))
108107

109108

110-
def draw_body(*args):
109+
def draw_body(data: dict):
111110
"""
112111
Place each section in its correct place by changing
113112
the coordinates on each loop.
114113
115114
Parameters
116115
----------
117-
*args : indexable object
116+
data : dict
118117
The input data (can be list or tuple). ValueError is
119118
raised if more than six arguments are passed.
120119
@@ -127,18 +126,18 @@ def draw_body(*args):
127126
third_sections = []
128127
# Resize diagram to automatically scale in response to the number
129128
# of problems in the input data.
130-
if len(args) == 1 or len(args) == 2:
129+
if len(data) == 1 or len(data) == 2:
131130
spine_length = (-2.1, 2)
132131
head_pos = (2, 0)
133132
tail_pos = ((-2.8, 0.8), (-2.8, -0.8), (-2.0, -0.01))
134133
first_section = [1.6, 0.8]
135-
elif len(args) == 3 or len(args) == 4:
134+
elif len(data) == 3 or len(data) == 4:
136135
spine_length = (-3.1, 3)
137136
head_pos = (3, 0)
138137
tail_pos = ((-3.8, 0.8), (-3.8, -0.8), (-3.0, -0.01))
139138
first_section = [2.6, 1.8]
140139
second_sections = [-0.4, -1.2]
141-
else: # num == 5 or 6
140+
else: # len(data) == 5 or 6
142141
spine_length = (-4.1, 4)
143142
head_pos = (4, 0)
144143
tail_pos = ((-4.8, 0.8), (-4.8, -0.8), (-4.0, -0.01))
@@ -147,7 +146,7 @@ def draw_body(*args):
147146
third_sections = [-1.5, -2.3]
148147

149148
# Change the coordinates of the annotations on each loop.
150-
for index, problem in enumerate(args):
149+
for index, problem in enumerate(data.values()):
151150
top_row = True
152151
cause_arrow_y = 1.7
153152
if index % 2 != 0: # Plot problems below the spine.
@@ -168,33 +167,37 @@ def draw_body(*args):
168167
cause_arrow_x = third_sections[1]
169168
if index > 5:
170169
raise ValueError(f'Maximum number of problems is 6, you have entered '
171-
f'{len(args)}')
170+
f'{len(data)}')
172171

173172
# 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)
175174
# draw fish head
176175
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')
179178
ax.add_patch(semicircle)
180179
# draw fishtail
181-
triangle = Polygon(tail_pos, fc=COLOR)
180+
triangle = Polygon(tail_pos, fc='tab:blue')
182181
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.
185186
causes(problem, cause_arrow_x, cause_arrow_y, top=top_row)
186187

187188

188189
# 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)
200203
plt.show()

0 commit comments

Comments
 (0)
0