Search code examples
matplotlibvisualizationoverlap

matplotlib - visualisation of overlapping ranges


I want to show how two values overlap each other in x and y axes. In my case these are some observation data in form of time series, but I believe that this is not relevant.

I would like to achieve something like this: http://druid.if.uj.edu.pl/~pawel/rect3001.png Is it possible in matplotlib?


Solution

  • Here's a good example. I adapted it slightly from the gallery.

    import numpy as np
    import matplotlib.cm as cm
    from matplotlib.pyplot import figure, show, rc
    
    
    # force square figure and square axes looks better for polar, IMO
    fig = figure(figsize=(8,8))
    ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=False)
    
    N = 20
    theta = np.arange(0.0, 2*np.pi, 2*np.pi/N)
    radii = 10*np.random.rand(N)
    width = np.pi/4*np.random.rand(N)
    bars = ax.bar(theta, radii, width=width, bottom=0.0)
    for r,bar in zip(radii, bars):
        bar.set_facecolor( cm.jet(r/10.))
        bar.set_alpha(0.5)
    
    show()
    

    Overlapping bars.