2

So I have a dataframe which I have plotted and looks great using the code below. The issue is that there are ~10 colors being used and repeated for multiple enteries in the dataframe so that it is impossible to distinguish one dataframe entry from 20 others.

I figure there must be some way to state 'use X color scheme and allow for 60 colors' but I dont know how when using a dataframe.

dataframe = pd.DataFrame(new_vals)
dataframe.plot(kind='bar',stacked=True,legend=False, ylim=(0,100),title='Taxonomic analysis of samples')

N = 29
ind = np.arange(N)
width = 0.35




plt.xlabel('Sample')
plt.ylabel('Percentage of assembly atrribted to each taxonomic group (%)')
plt.legend(loc="best", bbox_to_anchor=(1.0, 1.00))
plt.xticks(ind+width/2. - 0.2,('B11', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'C10', 'C11', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'D10', 'D11', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9'))

Here is an example of my dataframe;

    Other   actinomyces alcanivorax alkaliphilus    bacillus    bacteroides candidatus phytoplasma  cyanothece  enterobacter    escherichia ... neisseria   paenibacillus   porphyromonas   prevotella  pseudoalteromonas   rothia  staphylococcus  streptococcus   streptomyces    veillonella
0   26.229808   5.198240    4.694513    0.047974    3.691476    0.792203    2.782495    2.018697    2.180294    0.453228    ... 1.677198    4.944483    0.458910    5.496815    2.910004    0.372430    0.599676    8.276785    1.992817    0.595257
1   24.395006   11.615767   1.995668    0.069200    5.750399    0.921047    1.248692    0.740260    0.967860    1.904479    ... 0.873587    1.316648    0.261579    4.954371    1.348089    2.405995    1.061885    18.200302   1.660959    5.382657
2   22.078940   5.772762    3.107776    0.070983    5.523827    1.428608    1.846615    1.218850    1.542251    1.656823    ... 0.986514    2.414715    0.617899    6.893698    2.014352    0.496304    1.056452    22.272679   1.470803    2.696270
3   33.438669   5.210649    0.043170    0.136277    7.108181    2.148167    0.071589    0.034340    0.073281    2.719497    ... 1.922939    0.111153    3.898990    6.426144    0.045960    4.365727    1.545480    17.170125   0.870670    3.480261
4   20.831026   3.001972    4.746576    0.034374    2.198009    0.677926    3.264413    2.524014    2.720162    0.563074    ... 1.167616    9.110402    0.358742    3.323339    3.180934    0.420669    0.408120    8.948355    1.856454    1.086865

1 Answer 1

3

IIUC you can generate a colormap of kcolors with a function like the following:

def colormapgenerator(N, cm=None):

    base = plt.cm.get_cmap(cm)
    color_list = base(np.linspace(0, 1, N))
    cm_name = base.name + str(N)
    return base.from_list(cm_name, color_list, N)

where cm is your desidered cmap (e.g. Blues, Reds etc), and N is the number of colors you need. Than try to add to your dataframe.plot() the following:

cmap=colormapgenerator(60, 'Reds')

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.