0

I have a six-axes matplotlib figure, and i would like to draw a simple horizontal red line for x=2 over the whole figure. Is that possible ?

I saw this : Matplotlib: Can a plot a line from one set of axes to another? which is promising, but a bit complex - is there another simpler way ?

fig , axes = plt.subplots(1,6)
iteration  = -1

for label, group in  X.groupby(["quantile_Y"])["FTE"]:
    iteration       +=1
    to_draw          = axes[iteration]
    local_title      = "Y < "+label[label.find(",")+2:-5]
    group.plot(kind  = "box"         ,  
               ax    = to_draw       , 
               ylim  = (0,5)         ,  
               title = local_title   )

    to_draw.label_outer()
    to_draw.set_axis_bgcolor("white")
    to_draw.plot([0,0], [10,10])
plt.show()`

Which gives me :

enter image description here

It is clear that a straight line at x=2 could be useful ;)

Community
  • 1
  • 1
Romain Jouin
  • 4,448
  • 3
  • 49
  • 79
  • why are you plotting on separate axes? – Paul H Aug 04 '16 at 22:03
  • I don't know... can we plot on the same one ? – Romain Jouin Aug 04 '16 at 22:13
  • http://matplotlib.org/devdocs/gallery.html#statistics and http://stanford.edu/~mwaskom/software/seaborn/examples/grouped_boxplot.html – Paul H Aug 04 '16 at 22:14
  • and here's a questions about horizontal lines and subplots, found by searching the matplotlib tag for "horizontal line" http://stackoverflow.com/questions/21129007/plotting-a-horizontal-line-on-multiple-subplots-in-python-using-pyplot – Paul H Aug 04 '16 at 22:17
  • ... Well I had a look at http://matplotlib.org/devdocs/examples/statistics/boxplot_demo.html and I still see they use several axes. As for http://stanford.edu/~mwaskom/software/seaborn/examples/grouped_boxplot.html It doesn't really fit my need I think. – Romain Jouin Aug 05 '16 at 15:21
  • The same : http://stackoverflow.com/questions/21129007/plotting-a-horizontal-line-on-multiple-subplots-in-python-using-pyplot doesn't answer needer the question I think, as it is plotting an horizontal by axis, and not one through different axis – Romain Jouin Aug 05 '16 at 15:23
  • And upon further inspection, I'm sure you'll notice that each of the examples has multiple boxes on each of the individual axes objects. – Paul H Aug 05 '16 at 15:47
  • I don't know, if I see : fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(6, 6), sharey=True) axes[0, 0].boxplot(data, labels=labels) axes[0, 0].set_title('Default', fontsize=fs) axes[0, 1].boxplot(data, labels=labels, showmeans=True) axes[0, 1].set_title('showmeans=True', fontsize=fs) To me this is like two axes – Romain Jouin Aug 05 '16 at 15:49
  • two axes, each with multiple boxes -- are you looking at the images? – Paul H Aug 05 '16 at 15:52
  • ... you may be right... – Romain Jouin Aug 05 '16 at 16:01
  • How would you prepare the data to do the whole in one row ? Have to make a dataframe with one column by subset, and a line by quantile ? – Romain Jouin Aug 05 '16 at 16:05
  • list of 1-D arrays – Paul H Aug 05 '16 at 16:06
  • `X.groupby` implies you have dataframe: http://pandas.pydata.org/pandas-docs/stable/visualization.html#box-plots – Paul H Aug 05 '16 at 16:07

0 Answers0