Skip to content

Commit c0c6668

Browse files
committed
Follow-up on issue #92 : seaborn-blind error
- fixed plot.py and distribution.py related to get_next_color() - removed ax in results.py since get_next_color() doesn't accept params from now additional fix
1 parent 3ec60a1 commit c0c6668

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

symbulate/distributions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def plot(self, xlim=None, alpha=None, ax=None, **kwargs):
8585
ax.set_ylim(*ylim)
8686

8787
# get next color in cycle
88-
color = get_next_color(ax)
88+
89+
color = get_next_color()
8990

9091
# plot points for discrete distributions
9192
if self.discrete:

symbulate/plot.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
xlim = plt.xlim
1313
ylim = plt.ylim
1414

15+
color_index=0
16+
color_cycle = [c['color'] for c in plt.rcParams['axes.prop_cycle']]
17+
1518
def init_color():
1619
hex_list = [colors.rgb2hex(rgb) for rgb in plt.cm.get_cmap('tab10').colors]
1720
plt.rcParams["axes.prop_cycle"] = cycler('color', hex_list)
1821

19-
def get_next_color(axes):
20-
color_cycle = axes._get_lines.prop_cycler
21-
color = next(color_cycle)["color"]
22+
def get_next_color():
23+
global color_index
24+
color = color_cycle[color_index]
25+
color_index = (color_index + 1) % len(color_cycle)
2226
return color
2327

2428
def configure_axes(axes, xdata, ydata, xlabel = None, ylabel = None):

symbulate/results.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def plot(self, type=None, alpha=None, normalize=True, jitter=False,
473473
# initialize figure
474474
fig = plt.gcf()
475475
ax = plt.gca()
476-
color = get_next_color(ax)
476+
color = get_next_color()
477477

478478
if 'density' in type:
479479
if discrete:
@@ -545,27 +545,27 @@ def plot(self, type=None, alpha=None, normalize=True, jitter=False,
545545
x_lines = np.linspace(min(x), max(x), 1000)
546546
y_lines = np.linspace(min(y), max(y), 1000)
547547
ax_marg_x.plot(x_lines, densityX(x_lines), linewidth=2,
548-
color=get_next_color(ax))
548+
color=get_next_color())
549549
ax_marg_y.plot(y_lines, densityY(y_lines), linewidth=2,
550-
color=get_next_color(ax),
550+
color=get_next_color(),
551551
transform=Affine2D().rotate_deg(270) + ax_marg_y.transData)
552552
else:
553553
if discrete_x:
554-
make_marginal_impulse(x_count, get_next_color(ax), ax_marg_x, alpha, 'x')
554+
make_marginal_impulse(x_count, get_next_color(), ax_marg_x, alpha, 'x')
555555
else:
556-
ax_marg_x.hist(x, color=get_next_color(ax), density=normalize,
556+
ax_marg_x.hist(x, color=get_next_color(), density=normalize,
557557
alpha=alpha, bins=bins)
558558
if discrete_y:
559-
make_marginal_impulse(y_count, get_next_color(ax), ax_marg_y, alpha, 'y')
559+
make_marginal_impulse(y_count, get_next_color(), ax_marg_y, alpha, 'y')
560560
else:
561-
ax_marg_y.hist(y, color=get_next_color(ax), density=normalize,
561+
ax_marg_y.hist(y, color=get_next_color(), density=normalize,
562562
alpha=alpha, bins=bins, orientation='horizontal')
563563
plt.setp(ax_marg_x.get_xticklabels(), visible=False)
564564
plt.setp(ax_marg_y.get_yticklabels(), visible=False)
565565
else:
566566
fig = plt.gcf()
567567
ax = plt.gca()
568-
color = get_next_color(ax)
568+
color = get_next_color()
569569

570570
nullfmt = NullFormatter() #removes labels on fig
571571

@@ -605,7 +605,7 @@ def plot(self, type=None, alpha=None, normalize=True, jitter=False,
605605
if alpha is None:
606606
alpha = np.log(2) / np.log(len(self) + 1)
607607
ax = plt.gca()
608-
color = get_next_color(ax)
608+
color = get_next_color()
609609
for result in self.results:
610610
result.plot(alpha=alpha, color=color, **kwargs)
611611
plt.xlabel("Index")

0 commit comments

Comments
 (0)