-1

With the following code, I try to plot 12 different histograms in one picture using Matplotlib.

for graph in range(1,13):
    name = all_results[graph-1]
    plt.subplot(4,3,graph, 
                title = name)
    plt.tight_layout()
    current_model = name
    plt.hist(all_val_accuracies[current_model],
             #range = (0.49, 0.58),
             bins = 50)
    plt.xlabel('Accuracy')
    plt.ylabel('Frequency')
    plt.axis([0.48, 0.58, 0, 50])

With this code, all histograms are plotted in one image as how I indicated it.

However, the graphs itself are squeezed to such an extend that you cant see them anymore

What can I do so that these 12 histograms are plotted in one image and that each histogram can be seen clearly?

Emil
  • 1,531
  • 3
  • 22
  • 47

1 Answers1

0

You should be able to set the size of your plots with

matplotlib.Figure.set_size_inches

To use this you will need to save the Figure object. You can include this in your code like this :

for graph in range(1,13):
    name = all_results[graph-1]
    fig, axs = plt.subplot(4,3,graph, 
                           title = name)
    plt.tight_layout()
    current_model = name
    plt.hist(all_val_accuracies[current_model],
             #range = (0.49, 0.58),
             bins = 50)
    fig.set_size_inches(12, 12)
    plt.xlabel('Accuracy')
    plt.ylabel('Frequency')
    plt.axis([0.48, 0.58, 0, 50])
Xb19
  • 130
  • 2
  • 10
  • Could you show how I can include this in my code? Im new to Matplotlib and still struggle a bit with its logic – Emil Jul 16 '18 at 12:38