2016-07-26 71 views
0

我在另一个问题上寻求帮助,当我尝试答案的代码时,我得到了不同的图片。我真的希望我的情节与答案作者生成的情节相同。我正在使用spyder/pycharm来生成图片。matplotlib/python相同的代码生成不同的地块?

我没有更改任何matplotlib常规设置。

守则

l = [23948.30, 23946.20, 23961.20, 23971.70, 23956.30, 23987.30] 

def box_plot(circ_list): 
    fig, ax = plt.subplots() 
    plt.boxplot(circ_list, 0, 'rs', 0, showmeans=True) 
    plt.ylim((0.28, 1.5)) 
    ax.set_yticks([]) 
    labels = ["{}".format(int(i)) for i in ax.get_xticks()] 
    ax.set_xticklabels(labels) 
    ax.spines['right'].set_color('none') 
    ax.spines['top'].set_color('none') 
    ax.spines['left'].set_color('none') 
    ax.spines['bottom'].set_position('center') 
    ax.spines['bottom'].set_color('none') 
    ax.xaxis.set_ticks_position('bottom') 
    plt.show() 

box_plot(l) 

答案的情节

http://i.stack.imgur.com/EFilf.png

我的阴谋

enter image description here

这是相关的问题,我从拿到代码:(还没有解决还请大家帮忙)

python/matplotlib/seaborn- boxplot on an x axis with data points

+0

您可能需要重新写你的问题。我们不知道whT的意思是“我真的更喜欢从答案的代码生成的情节。”只需阅读[帮助]中的条目即可了解如何编写有效的问题。 – boardrider

+0

已更改。 @boardrider – KKlalala

+1

你在生成你的情节之前先导入了seaborn。这弄乱了你所有的matplotlib预设。 –

回答

0

像@Mad物理学家pointed out in the commentsseaborn变化众多的款式和情节的特点:

代码1

import matplotlib.pyplot as plt 

l = [23948.30, 23946.20, 23961.20, 23971.70, 23956.30, 23987.30] 

def box_plot(circ_list): 
    fig, ax = plt.subplots() 
    plt.boxplot(circ_list, 0, 'rs', 0, showmeans=True) 
    plt.ylim((0.28, 1.5)) 
    ax.set_yticks([]) 
    labels = ["{}".format(int(i)) for i in ax.get_xticks()] 
    ax.set_xticklabels(labels) 
    ax.spines['right'].set_color('none') 
    ax.spines['top'].set_color('none') 
    ax.spines['left'].set_color('none') 
    ax.spines['bottom'].set_position('center') 
    ax.spines['bottom'].set_color('none') 
    ax.xaxis.set_ticks_position('bottom') 
    plt.savefig('box.png') 
    plt.show() 

box_plot(l) 

图1:

enter image description here

代码2

import matplotlib.pyplot as plt 
import seaborn as sns   # <--- Only change!! 

l = [23948.30, 23946.20, 23961.20, 23971.70, 23956.30, 23987.30] 

def box_plot(circ_list): 
    fig, ax = plt.subplots() 
    plt.boxplot(circ_list, 0, 'rs', 0, showmeans=True) 
    plt.ylim((0.28, 1.5)) 
    ax.set_yticks([]) 
    labels = ["{}".format(int(i)) for i in ax.get_xticks()] 
    ax.set_xticklabels(labels) 
    ax.spines['right'].set_color('none') 
    ax.spines['top'].set_color('none') 
    ax.spines['left'].set_color('none') 
    ax.spines['bottom'].set_position('center') 
    ax.spines['bottom'].set_color('none') 
    ax.xaxis.set_ticks_position('bottom') 
    plt.savefig('box.png') 
    plt.show() 

box_plot(l) 

剧情2:

enter image description here

相关问题