0

I found this related, older question. Sadly. the error_kw does not exist anymore (using matplotlib version 1.5.0). The capprops dictionary indeed only works on the cap.

I would like to change the line that extends from the box to the cap. Default is dashed blue, as seen below. I tried all the documented format dicts, but none of them is responsible for this line.

example boxplot with indication of what I would like to change

1 Answer 1

4

These are the "whiskers" and are returned by boxplot. Iterate over them and set the style accordingly:

import matplotlib.pyplot as plt
import numpy as np

# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low), 0)

plt.figure()
bp = plt.boxplot(data, 1)

for whisker in bp['whiskers']:
    whisker.set(color='#ff0000',lw=2)
plt.show()

enter image description here

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

3 Comments

wow, I completely missed that one. thanks for the quick answer, I cannot even accept it yet (:
No worries. You can set the cap styles to match by iterating over bp['caps'], by the way.
Nice answer. You can even do it without the explicit loop: plt.setp(bp['whiskers'], color='#ff0000', lw=2)

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.