1
import palettable
bmap = palettable.tableau.Tableau_20.mpl_colors

all_markers = ['s', 'o', '^', '*', 'v'] * 100

max_values = len(bmap) if len(bmap) < len(all_markers) else len(all_markers)

# Make sure equal number of cycle elements for color and markers
markers = all_markers[:max_values]
bmap = bmap[:max_values]

color_cycle = cycler('color', bmap)  # color cycle
marker_cycle = cycler('marker', markers)  # marker cycle

plt.rc('axes', prop_cycle=(color_cycle + marker_cycle))

I use the above code to cycle through a combination of colors and markers for some plots. However, this messes up a seaborn swarmplot I am using by replacing the dot markers. The dataframe used in boxplot and swarmplot is this:

        Poor     Watch  Favourable  Exceptional
0   0.256667  0.186000    0.100667     0.456667
1   0.259333  0.150000    0.181333     0.409333
2   0.360000  0.200667    0.158667     0.280667
3   0.380667  0.217333    0.109333     0.292667
4   0.258667  0.141333    0.150667     0.449333
5   0.210000  0.146000    0.167333     0.476667
6   0.794667  0.052000    0.056000     0.097333
7   0.269333  0.157333    0.112000     0.461333
8   0.338667  0.230667    0.119333     0.311333
9   0.716000  0.092000    0.084000     0.108000
10  0.627333  0.103333    0.124000     0.145333
11  0.332667  0.171333    0.098667     0.397333
12  0.331333  0.210000    0.122667     0.336000
13  0.417333  0.164667    0.108000     0.310000

The code is here:

# Copy the data above
import pandas
import matplotlib.pyplt as plt
import seaborn as sns
df = pandas.read_clipboard()
ax = sns.boxplot(data=df, linewidth=1.5, width=0.25)
# stackoverflow.com/questions/34163622/seaborn-passes-kwargs-to-plt-boxplot
plt.setp(ax.artists, alpha=.3, fill=False)
ax = sns.swarmplot(data=df, color='.25')
plt.setp(ax.artists, alpha=.6)

ax.set_ylabel('Class probability')
ax.set(ylim=(0, 1.0))

plt.tight_layout()
plt.show()

Here is the resulting graphic. I want to ensure that the dot markers are not replaced. How do I do that?

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
user308827
  • 21,227
  • 87
  • 254
  • 417
  • It would be more helpful if you could make the example minimal and complete — a block of code that someone could copy and paste to start developing the answer to your question. – mwaskom Feb 20 '16 at 16:51
  • Also, just looking at the plot, I think the unusual markers you're getting are part of the boxplot, not the swarmplot. – mwaskom Feb 20 '16 at 19:15
  • thanks @mwaskom, added the data used in the dataframe and completed the code as well. both the boxplot and swarmplot are coming from seaborn. thanks again! – user308827 Feb 21 '16 at 03:30
  • It is still not possible to copy and paste your example. – mwaskom Feb 21 '16 at 17:12
  • sorry @mwaskom, is it reading the dataframe? I added a read_clipboard() – user308827 Feb 21 '16 at 17:53

0 Answers0