0

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

https://i.sstatic.net/EFilf.png

My plot

enter image description here

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

4
  • You may want to re-write your question. We do not know whT is meant by "I really prefer the plot that was generated from the answer's code." Just read the entries in help center to understand how to write an effective question. Commented Jul 27, 2016 at 11:40
  • It's changed. @boardrider Commented Jul 27, 2016 at 15:29
  • 1
    You imported seaborn before generating your plot. That messes up all your matplotlib presets. Commented Jul 27, 2016 at 15:35
  • 1
    Show all your imports or your code is incomplete. Commented Jul 27, 2016 at 15:36

1 Answer 1

0

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:

enter image description here

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:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.