Didac Busquets
Didac Busquets

Reputation: 635

Show frequency in a violin plot

I'm using matplotlib's violinplot and I'd like to see the frequency values in the X axis.

This is my MWE:

import numpy as np
import matplotlib.pyplot as plt

data = np.random.normal(size=100)
plt.violinplot(data)
plt.show()

which generates the following plot: enter image description here

I'd like the X axis to show the frequency (count of values). Is that possible?

Upvotes: 0

Views: 36

Answers (1)

mozway
mozway

Reputation: 260290

Violin plots are using KDEs. The "X" value is a density (the total area of one half sums to 1). Thus, it doesn't really make sense to show "counts".

It looks like you rather want a hist, in which you can define the exact bins:

plt.hist(data)

Output:

enter image description here

Upvotes: 0

Related Questions