Search code examples
pythonchartsbar-chartsample

Print bar inside bar with mathplotlib python


I'm trying to make a bar chart using python mathplotlib. My chart must be this:

enter image description here

But I can't draw the bar that contains the sub-bars. Does anyone know how to do this? Thanks in advance


Solution

  • Here is a small example, which plots bars inside bars:

    import matplotlib.pyplot as plt
    
    y1 = [1, 2]
    x1 = [1, 3]
    
    y2 = [0.5, 0.7, 0.6, 0.9]
    x2 = [0.7, 1.3, 2.7, 3.3]
    
    plt.bar(x1, y1, width=1.5)
    plt.bar(x2, y2, width=0.5)
    

    I don't think, that this is your actual problem. What precisely do you need?