简体   繁体   中英

Avoid overlapping on seaborn plots

I'm making some EDA using pandas and seaborn, this is the code I have to plot the histograms of a group of features:

skewed_data =  pd.DataFrame.skew(data)
skewed_features =skewed_data.index

fig, axs = plt.subplots(ncols=len(skewed_features))
plt.ticklabel_format(style='sci', axis='both', scilimits=(0,0))
for i,skewed_feature in  enumerate(skewed_features):
    g = sns.distplot(data[column])  
    sns.distplot(data[skewed_feature],  ax=axs[i])

This is the result I'm getting:

在此处输入图片说明

Is not readable, how can I avoid that issue?

I know you are concerning about the layout of the figures. However, you need to first decide how to represent your data. Here are two choices for your case

(1) Multiple lines in one figure and

(2) Multiple subplots 2x2, each subplot draws one line.

I am not quite familiar with searborn, but the plotting of searborn is based on matplotlib. I could give you some basic ideas.

To archive (1), you can first declare the figure and ax, then add all line to this ax. Example codes:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
# YOUR LOOP, use the ax parameter
for i in range(3)
    sns.distplot(data[i], ax=ax)

To archive (2), same as above, but with different number subplots, and put your line in the different subplot.

# Four subplots, 2x2
fig, axarr = plt.subplots(2,2)
# YOUR LOOP, use different cell

You may check matplotlib subplots demo . To do a good visualization is a very tough work. There are so many documents to read. Check the gallery of matplotlib or seaborn is a good and quick way to understand how some kinds of visualization are implemented.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM