I made a histogram on the Jupyter Notebook in Python. This histogram was performed by counting the number of equilateral triangles present in a sample and measuring its lateral size. Then the relative frequency was calculated. In this histogram I wanted to place a brokenaxes
with this package, on the xx axis.
I wanted to eliminate empty spaces that range from 2.25 to 7.75. How could I do that? I had already tried using this package but the graphic always appeared unformatted. The goal is to reduce the x-axis to be able to make the graph larger, since the numbers on the x-axis appear very small. I would also like to know how to place a distribution line in the histogram.
I had already experimented with a Gaussian, but I don't think it fits the data well. I don't know if the ones that adapt best are gamma, log-normal or poisson and I don't know how to add the distribution line to the graph. I really appreciate your help.
I'll put here the code I used to make the graph and the Gaussian distribution:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm
import matplotlib.ticker as tkr
import scipy, pylab
import locale
locale.setlocale(locale.LC_NUMERIC, "de_DE")
plt.rcParams['axes.formatter.use_locale'] = True
df=pd.DataFrame({'frequencia_relativa': {'0-0,25': 0.076, '0,25-0,50': 0.1591,
'0,50-30,75': 0.3030, '0,75-1,00': 0.2045,
'1,00-1,25': 0.1288, '1,25-1,50': 0.1288,
'1,50-1,75': 0.0530, '1,75-2,00': 0.0000,
'2,00-2,25': 0.0076, '2,25-2,50': 0.0,
'2,50-2,75': 0.0, '2,75-3,00': 0.00,
'3,25-3,50': 0.00, '3,50-3,75': 0.00,
'3,75-4,00': 0.00, '4,00-4,25': 0.00,
'4,25-4,50': 0.00, '4,50-4,75': 0.00,
'4,75-5,00': 0.00, '5,25-5,50': 0.00,
'5,50-5,75': 0.00, '5,75-6,00': 0.00,
'6,00-6,25': 0.00, '6,25-6,50': 0.00,
'6,50-6,75': 0.00, '6,75-7,00': 0.00,
'7,00-7,25': 0.00, '7,25-7,50': 0.00,
'7,50-7,75': 0.00, '7,75-8,00': 0.0076}})
df=df.reindex(['0-0,25', '0,25-0,50', '0,50-30,75', '0,75-1,00', '1,00-1,25', '1,25-1,50',
'1,50-1,75', '1,75-2,00', '2,00-2,25', '2,25-2,50', '2,50-2,75', '2,75-3,00',
'3,25-3,50', '3,50-3,75', '3,75-4,00', '4,00-4,25', '4,25-4,50', '4,50-4,75',
'4,75-5,00', '5,25-5,50', '5,50-5,75', '5,75-6,00', '6,00-6,25', '6,25-6,50',
'6,50-6,75', '6,75-7,00', '7,00-7,25', '7,25-7,50', '7,50-7,75', '7,75-8,00'])
plt.rcParams["figure.figsize"] = [70,8]
fig, ax =plt.subplots()
ax.bar(x=df.index, height=df.frequencia_relativa, alpha=0.5, width=0.9)
ax.set_xlabel('Tamanho lateral do triângulo ($\mu m$)', fontsize=22)
ax.set_ylabel('Frequência relativa', fontsize=22)
x_axis = np.arange(0, 29, 0.001)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
ax.plot(x_axis, norm.pdf(x_axis,0.903,0.713), linewidth=3)
#plt.show()
plt.savefig('output.png', dpi=500, bbox_inches='tight')