2016-07-26 74 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

相關問題