1

Let's say I did 16 experiments replicated 3 times for a total of 48 measures. Here's an example of my dataframe and a snippet that replicates my problem:

import numpy as np import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame(np.abs(np.random.randn(48, 4)), columns=list("ABCD")) color_list = plt.cm.gnuplot(np.linspace(0,1,16)) df.A.plot.bar( figsize=(16,7), color=color_list) plt.axvline(15.5, c="black", lw=1) plt.axvline(31.5, c="black", lw=1) plt.plot() 

And here's the output of the graph:

Problematic Barplot

So, the vertical lines represents each replica, there is 16 bars in each. My color list is also of length 16 so I would expect to have 3 times the same colors, but at 16 and 17, there is two black bars (which is the 0th color in the list) and at 32, there is this yellow bar that comes from the offset caused by the second black line at 17. Followed by 2 black lines again.

It looks like my color_list puts a 0 automatically when it starts for the second time.

Edit : My temporary solution was to create a list of length 48 that is the first list repeated 3 times:

lst=list(np.linspace(0,1,16)) liste = lst + lst + lst color_list = plt.cm.gnuplot(liste) 
4
  • 1
    It seems this comes from pandas, using matplotlib along doesn't have such problem. Commented Apr 17, 2018 at 21:38
  • Can you paste the line of code you used to give the same graph with only matplotlib ? Commented Apr 18, 2018 at 16:46
  • 1
    You can use plt.figure(figsize=(16,7)) plt.bar(range(len(df.A)), df.A, color=color_list) but you will need to tweak the axis and a few other things. Commented Apr 18, 2018 at 17:35
  • I've created a PR to pandas to fix the bug as well. You can use that one if you wish. github.com/pandas-dev/pandas/pull/20727 Commented Apr 18, 2018 at 17:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.