Two sea slots on one axis

I am trying to find a good way to build two distplots (from seaborn) on the same axis. This is not as beautiful as I want, since the histograms cover each other. And I do not want to use it countplotor barplotsimply because they do not look beautiful. Naturally, if there is no other way, I will do it this way, but distplotit looks very good. But, as said, the stripes now cover each other (see. Fig.).

Thus, is there a way to set the two frequency bands of the scatter per box so that they do not overlap? Or put the counts on top of each other? Basically I want to do this in the sea:

enter image description here

Any ideas on cleaning it are welcome. Thanks.

MWE:

sns.set_context("paper",font_scale=2)
sns.set_style("white")
rc('text', usetex=False)
fig, ax = plt.subplots(figsize=(7,7),sharey=True)
sns.despine(left=True)

mats=dict()
mats[0]=[1,1,1,1,1,2,3,3,2,3,3,3,3,3]
mats[1]=[3,3,3,3,3,4,4,4,5,6,1,1,2,3,4,5,5,5]
N=max(max(set(mats[0])),max(set(mats[1])))

binsize = np.arange(0,N+1,1)
B=['Thing1','Thing2']
for i in range(len(B)):
    ax = sns.distplot(mats[i],
                      kde=False,
                      label=B[i],
                      bins=binsize)

ax.set_xlabel('My label')
ax.get_yaxis().set_visible(False)
ax.legend()
plt.show()

enter image description here

+4
1

@mwaskom , matplotlib ( ), .

, , " ", matplotlib:

sns.set_context("paper", font_scale=2)
sns.set_style("white")
plt.rc('text', usetex=False)
fig, ax = plt.subplots(figsize=(4,4))
sns.despine(left=True)

# mats=dict()
mats0=[1,1,1,1,1,2,3,3,2,3,3,3,3,3]
mats1=[3,3,3,3,3,4,4,4,5,6,1,1,2,3,4,5,5,5]
N=max(mats0 + mats1)

# binsize = np.arange(0,N+1,1)
binsize = N
B=['Thing1','Thing2']

ax.hist([mats0, mats1], binsize, histtype='bar', 
        align='mid', label=B, alpha=0.4)#, rwidth=0.6)

ax.set_xlabel('My label')
ax.get_yaxis().set_visible(False)
# ax.set_xlim(0,N+1)
ax.legend()
plt.show()

:

enter image description here

ax.set_xlim(0,N+1), .

+4

Source: https://habr.com/ru/post/1626564/


All Articles