So I have a lot of discrete variables in my dataset and want to visualize them (univariate for now). I went through various articles over the internet and it is suggested that histograms and count plots are apt choices for plotting discrete data. Many of the discrete variables in my dataset have 500+ unique discrete values and when I plot them on a histogram it is taking a lot of time to show my any output. So is my approach correct?, can we actually plot these many unique valued discrete variables using a histogram? or do you suggest any other type of plot for the same?

Edit : Just got the output for a variable with 400+ discrete values and the histogram (sns.histplot) is empty, the x and y axis are visible but there are no bars in the histogram. Why would that be?

I have attached a reference photo of my column with the value_counts() function's output. There are about 400 discrete values

  • 1
    $\begingroup$ Can you show us a sample of how your discrete dataset and a picture of your histogram? $\endgroup$ Commented Jun 19, 2021 at 12:59

1 Answer 1


[completely edited after clarification from OP]

A histogram is built by making bins of equal size across the range of values taken by the variable. For example if the variable ranges from 0 to 500 one might decide to create 50 bins of size 10. Then the actual values of the distribution are counted by bin: every value between 0 and 9 goes into the first bin, every value between 10 and 19 goes into the second bin etc.

The number of discrete values does not matter (in fact the values can be continuous) because the values are binned, i.e. they are grouped by how close they are to each other (with arbitrary interval bounds).

I can see that the data you have is already formatted as

<value> <frequency>

The problem you have certainly comes from the fact that this format is incorrect for the function: typically histogram functions create the bins themselves, so there's no need to have counted the values beforehand. This means that you should provide a single vector containing all the values as many times as they occur.

Alternatively you could create the bins yourself beforehand: decide the intervals then count how many values in each bin. Then use a simple bar plot to show the count for every bin. This option is usually less convenient.

  • $\begingroup$ Okay I understood your point, but my data is numerical with discrete values (423 discrete values all numerical in nature) so a histogram can be formed using it right? $\endgroup$ Commented Jun 19, 2021 at 15:39
  • $\begingroup$ I have posted a photo as well now of my data for your reference $\endgroup$ Commented Jun 19, 2021 at 15:49
  • $\begingroup$ @ml_learner15 Ok I misunderstood, I thought by "discrete variables" you meant categorical. I'm going to edit my answer then. $\endgroup$
    – Erwan
    Commented Jun 19, 2021 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.