Seaborn BoxPlot和日志轴

时间:2018-03-16 16:03:55

标签: python pandas seaborn boxplot

从现在开始几个小时以来,我一直面临着蜱的问题。

我想绘制一个带有日志缩放的boxplot,但似乎有两个问题:

  

数据没有正值,因此无法进行对数缩放。

并且

  

尝试为对数刻度轴设置非正xlimits;无效限制将被忽略。

她是我的代码:

# Import librairies
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.ticker as ticker

# Undersampling the DataFrame through columns because too big
sampling_factor = 50

all_frame_inverted_undersampled = all_frame_inverted.take([x for x in range(0,all_frame_inverted.shape[1], sampling_factor)], axis=1)

# Settings the canvas
fig, ax= plt.subplots(figsize=(18, 6))
ax.set_xlabel('Cycles') 
ax.set_ylabel('Measures')

# setting log axis
ax.set_xscale('log')

# Plotting
g = sns.boxplot(data=all_frame_inverted_undersampled , palette='rainbow', orient="v", ax=ax)

# Showing
plt.tight_layout()

以下是3条第一行的DataFrame: enter image description here

在这里,我得到了什么: enter image description here

我尝试了许多设置: ax.xaxis.set_major_formatter(xmajor_formatter) with LogFormatter

我已尝试symlog,错误信息消失,但结果完全相同。

我也尝试过:ax.set_xscale('symlog', linthreshy=1e3)

  

EDIT   我试图在x轴上得到格式,如下图所示:   enter image description here

     

编辑2:这是我的代码的最小例子:

# Preprocessing and Cleaning data
import numpy as np
import pandas as pd

# Data Visualization
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
%matplotlib inline

# Data Analysis & Visualization
import seaborn as sns

# Data
data= [[181.08, 180.23, 181.60, 178.05, 172.33, 175.50, 169.81, 167.10, 166.92, 166.10, 159.69], 
       [144.94,140.30,140.15,146.07,143.90,143.06,139.74,139.97,144.06,145.13,146.34],
       [176.25,195.43,217.50,183.75,174.74,169.11,166.81,161.82,164.08,162.25,166.72],
       [198.31,221.16,214.19,209.06,202.08,180.08,185.79,181.73,178.95,179.53,189.08],
       [167.81,166.28,144.18,138.22,139.48,144.66,141.34,141.60,146.53,145.84,155.20]]

# Data to Dataframe
df = pd.DataFrame(data=data, index=['M01', 'M02', 'M03', 'M04', 'M05'], 
                  columns=[8796, 60501505, 142252576, 224057457, 305801670, 387546170, 487628661, 609874323, 732114489, 854385341, 1190477590])

# Boxplot calculated for each cycle through all structures Mxx
fig, ax= plt.subplots(figsize=(18, 6))
ax.set_xlabel('Cycles') 
ax.set_ylabel('Measures')
ax.set_xscale('symlog')
plt.xticks(rotation=45)
sns.boxplot(data=df, palette='rainbow', orient="v", ax=ax)


# Showing plot
plt.tight_layout()
     

enter image description here

     

这是我可以用Plotly做的,我希望使用boxplot这个结果   拜托:

 # Interactive Data Visualization needs : pip install plotly & pip install cufflinks
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import cufflinks as cf
df.iplot(kind='box', xTitle='Cycles', yTitle='Measures', logx=True) 
     

enter image description here

感谢您的帮助

0 个答案:

没有答案