1

I would like

(1) to create some distance between the title of the plot and the title of the subplots (at present the title of one of the subplots overlaps the title of the plot).

(2) the scientific notion of the axis to be displayed as 10 to the power of x rather than 1lx like in the figure below.

(3) to choose the number of ticks on the x and y axis of the subplots, by entering the number of ticks as an argument into the function. (In this example the y axis has too many ticks).

(4) create some distance between xlab & the x-values, and ylab & the y-values

The code and figure are below

from __future__ import division
import math
import numpy as np
import matplotlib.pyplot as plt

def distribution_histogram(data):
    rows_columns = int(math.sqrt(len(data)))
    fig, ax = plt.subplots(nrows=rows_columns, ncols=rows_columns, sharey=True, tight_layout=True)
    axs = ax.flatten()
    subtitle_symbol = r'$\alpha$'
    for i in xrange(len(data)):
        d = data[i]
        bins = len(d) / 10
        axs[i].hist(d, bins=bins)
        subtitle = subtitle_symbol + ' = '+ str(i)
        axs[i].set_title('%s' % subtitle)
        axs[i].ticklabel_format(style='sci', scilimits=(1,1), useOffset=True, useLocale=True, useMathText=True)


    title = 'Distribution of something'
    plt.suptitle('%s' % title)
    plt.tight_layout()
    fig.text(0.5, 0.0, 'xlab', ha='center')
    fig.text(0.0, 0.5, 'ylab', va='center', rotation='vertical')
    plt.savefig('%s.png' % 'distribution_file_name', bbox_inches='tight')


data = []
a = range(1,11)
a = a * 100
for i in xrange(9):
    d = np.random.uniform(0,a[i],100)
    data.append(d)

distribution_histogram(data)

enter image description here

user58925
  • 1,537
  • 5
  • 19
  • 28
  • Please do not ask 4 unrelated questions at once. If you have 4 problems, ask 4 questions. However, all of those questions have already been asked before in some way or another. According to [ask] you should mention in how far those do not solve the problem. – ImportanceOfBeingErnest Dec 23 '17 at 16:31
  • I marked as duplicate for the first of your questions for now. Please find the appropriate questions for the other points yourself. – ImportanceOfBeingErnest Dec 23 '17 at 16:33

0 Answers0