matplotlib/python相同的代码会生成不同的图吗? [英] matplotlib/python Same code generate different plots?
问题描述
我在另一个问题上寻求帮助,当我尝试答案的代码时,我得到了不同的画面.我真的希望我的情节与答案作者生成的情节相同.我正在使用 spyder/pycharm 生成图片.
我没有更改任何 matplotlib 常规设置.
代码
l = [23948.30,23946.20,23961.20,23971.70,23956.30,23987.30]def box_plot(circ_list):无花果,ax = plt.subplots()plt.boxplot(circ_list, 0, 'rs', 0, showmeans=True)plt.ylim((0.28, 1.5))ax.set_yticks([])标签 = ["{}".format(int(i)) for i in ax.get_xticks()]ax.set_xticklabels(标签)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('底部')plt.show()box_plot(l)
答案的情节
我的情节
这是我从那里得到代码的相关问题:(还没有解决,请帮忙)
代码 2
将matplotlib.pyplot导入为plt将seaborn导入为sns#< ---只能更改!!l = [23948.30、23946.20、23961.20、23971.70、23956.30、23987.30]def box_plot(circ_list):无花果,ax = plt.subplots()plt.boxplot(circ_list,0,'rs',0,showmeans = True)plt.ylim((0.28,1.5))ax.set_yticks([])标签 = ["{}".format(int(i)) for i in ax.get_xticks()]ax.set_xticklabels(标签)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('底部')plt.savefig('box.png')plt.show()box_plot(l)
情节 2:
I was asking for help in another question and when I try the answer's code I got a different picture. I really want my plot to be the same with the plot that was generated from the answer's author. I am using spyder/pycharm to generate the pictures.
I did not change any matplotlib general settings.
The Code
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)
The answer's plot
My plot
This is the related question where I got the code from:(also not solved yet please help)
python/matplotlib/seaborn- boxplot on an x axis with data points
Like @Mad Physicist pointed out in the comments, seaborn
changes many styles and features of the plots:
Code 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)
Plot 1:
Code 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)
Plot 2:
这篇关于matplotlib/python相同的代码会生成不同的图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!