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

Community
  • 1
  • 1
Faultier
  • 1,296
  • 2
  • 15
  • 21

1 Answers1

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

xnx
  • 24,509
  • 11
  • 70
  • 109
  • wow, I completely missed that one. thanks for the quick answer, I cannot even accept it yet (: – Faultier Nov 24 '15 at 11:38
  • 1
    No worries. You can set the cap styles to match by iterating over `bp['caps']`, by the way. – xnx Nov 24 '15 at 11:41
  • 1
    Nice answer. You can even do it without the explicit loop: `plt.setp(bp['whiskers'], color='#ff0000', lw=2)` – hitzg Nov 24 '15 at 14:50