0

I would like to know how I can generate a graph that increases in width with the number of subplots.

I am trying to create a graph which contains multiple boxplots:

def create_box_plot(vals_dict, max_val):
    fig = plt.figure()
    ax = plt.axes()
    
    # set axes limits and labels
    plt.ylim(0, max_val)
    plt.xticks(rotation=90)
    
    counter, positionss = 1, []
    # first boxplot pair
    for vals in vals_dict.values():
        positions = [i for i in range(counter, counter + len(vals))]
        positionss.append(positions)
        bp = plt.boxplot(vals, positions=positions, widths=0.6, showfliers=False)
        
        counter += len(vals) + 1
    
    ax.set_xticklabels(list(vals_dict.keys()))
    ax.set_xticks([np.mean(positions) for positions in positionss])
    
    buf = io.BytesIO()
    
    plt.savefig(buf, aspect='auto', dpi=300, format='png')
    buf.seek(0)
    plt.close() 

If I e.g. set the figzise to (20, 1), then for a large number of subplots I get a good enough looking graph: enter image description here

but if I only have a few boxplots or if the labels are long the graph looks awful: enter image description here

1 Answer 1

1

I don't think you mean subplots, you mean boxes in your plot, right?

Pass a figsize argument to plt.figure and make the figsize values a value dependant on the number of boxes you are going to plot.

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.