# Defining bin sizes for plotting histograms [duplicate]

Perhaps a basic question, but is there a method or definition of how to choose the optimum bin size for some data with the intent to plot as a histogram?

At present the best option I can think of is to fit distribution functions to the histograms and choose the bin size where the fit is best.

Is there a definition based on the data size or some other metric?