Matplotlib/python Same Code Generate Different Plots?
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
Solution 1:
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]
defbox_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]
defbox_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:
Post a Comment for "Matplotlib/python Same Code Generate Different Plots?"