Search code examples
pythonmatplotlibpolar-coordinates

Change the size of subplots for polar projection


I am plotting a 3x3 grid of polar projections (that look a bit like radar plots).

e.g. exactly as in this example: https://matplotlib.org/examples/pylab_examples/polar_demo.html

I am managing to plot the data as intended, but would now like to scale each polar projection by a variable, so that some of the circle are bigger than others, as in the figure below. scale either by width/height or area

What are the commands I need to apply to the axis as I cycle through subplots?

I have tried turning on/off autoscale. It is possible that gridspec.Gridspec() might work, but I'm not sure if this is the best solution, although it might well be. Thanks


Solution

  • Nice question.

    You can also use directly fig.add_axes() to have a continuous space in which you place your plots:

    f = plt.figure()
    ax = f.add_axes([0.05, 0.4, 0.2, 0.2], polar=True) # Left, Bottom, Width, Height
    ax2 = f.add_axes([0.30, 0.2, 0.6, 0.6], polar=True)
    r = np.arange(0, 2, 0.01)
    theta = 2 * np.pi * r
    ax.plot(theta, r)
    ax2.plot(theta, r)
    

    polar plot with different size


    Less good version

    You can try to set different Axes size when you create them:

    import numpy as np
    import matplotlib.pyplot as plt
    
    r = np.arange(0, 2, 0.01)
    theta = 2 * np.pi * r
    
    ax = plt.subplot2grid((2,3), (0,0), polar=True)
    ax2 = plt.subplot2grid((2,3), (0,1), rowspan=2, colspan=2, polar=True)
    ax.plot(theta, r)
    ax2.plot(theta, r)
    

    polar plot with different size

    You can have a bigger grid than 2x3 and have more granularity on the size of the plot.

    (Don't mind the different graphic styles)

    HTH