Repository: rootpy/rootpy

Issue:
roo2matplotlib creates only black and white print out
I'm trying to read a histogram from a ROOT file and to plot it with matplotlib (both as histogram and errobar).

Following code is used:

``` #!/usr/bin/python
import matplotlib
matplotlib.use('Agg') # do this before importing pyplot or root2matplotlib
from rootpy import ROOT 
import rootpy.plotting.root2matplotlib as rplt
from rootpy.io import root_open
import matplotlib.pyplot as plt
data = root_open("./391.0_data_kmu2.root");
data_plot = data.Get("cut_211111_MUVEfficiency")
rplt.hist(data_plot,  color="blue")
#rplt.errorbar(kmu3_data_plot, yerr=False, label="data", emptybins=False, fmt='r-')
rplt.errorbar(data_plot,label='bla', fmt='ro')

plt.savefig("./test.pdf")
```

This output is created:
![test](https://cloud.githubusercontent.com/assets/6237108/6315219/24c9bf48-b9fb-11e4-8c7c-93f161a3c00c.png)

As you see all my color commands are ignored. Do I miss something?



Discussion:
`root2matplotlib.hist` [doesn't pass](https://github.com/rootpy/rootpy/blob/b6331ccb0b5140fac9f8fbb11acb6db289ab7a00/rootpy/plotting/root2matplotlib.py#L284-L285) `color` to [`root2matplotlib.step`](https://github.com/rootpy/rootpy/blob/b6331ccb0b5140fac9f8fbb11acb6db289ab7a00/rootpy/plotting/root2matplotlib.py#L596-L634) (I think this is a bug), so the line colour is [taken from the ROOT histogram](https://github.com/rootpy/rootpy/blob/b6331ccb0b5140fac9f8fbb11acb6db289ab7a00/rootpy/plotting/root2matplotlib.py#L629-L630).  As a workaround you can set the colour before plotting:

``` python
data_plot = data.Get("cut_211111_MUVEfficiency")
data_plot.color = "blue"
rplt.hist(data_plot)
```

You can use any colour understood by either ROOT or matplotlib.

Thank you, with 

```
data_plot.color = "blue"
```

I can indeed change the line color.
![test](https://cloud.githubusercontent.com/assets/6237108/6315950/02c6f7ea-ba13-11e4-826d-de627f497257.png)

However, I seems I cannot change the fill color. At least neither
     data_plot.SetFillColor("blue") # nor
     data_plot.fillcolor = "blue"
has any effect.

Update:
To have fill following is needed:

```
data = root_open("./391.0_data_kmu2.root");
data_plot = data.Get("cut_211111_MUVEfficiency")
data_plot.SetColor("blue")
data_plot.fillcolor = "blue"
rplt.hist(data_plot,  fill=True, facecolor="blue")
```

![test](https://cloud.githubusercontent.com/assets/6237108/6316536/18a074e4-ba2a-11e4-9280-c1c06983b3ec.png)

The edge color is probably a bug.


Resolving patch:
diff --git a/rootpy/plotting/root2matplotlib.py b/rootpy/plotting/root2matplotlib.py
--- a/rootpy/plotting/root2matplotlib.py
+++ b/rootpy/plotting/root2matplotlib.py
@@ -53,11 +53,12 @@ def _set_defaults(obj, kwargs, types=['common']):
             defaults['linestyle'] = obj.GetLineStyle('mpl')
             defaults['linewidth'] = obj.GetLineWidth()
         elif key == 'fill':
-            defaults['edgecolor'] = obj.GetLineColor('mpl')
-            defaults['facecolor'] = obj.GetFillColor('mpl')
+            defaults['edgecolor'] = kwargs.get('color', obj.GetLineColor('mpl'))
+            defaults['facecolor'] = kwargs.get('color', obj.GetFillColor('mpl'))
             root_fillstyle = obj.GetFillStyle('root')
             if root_fillstyle == 0:
-                defaults['facecolor'] = 'none'
+                if not kwargs.get('fill'):
+                    defaults['facecolor'] = 'none'
                 defaults['fill'] = False
             elif root_fillstyle == 1001:
                 defaults['fill'] = True
@@ -268,7 +269,7 @@ def _hist(h, axes=None, bottom=None, logy=None, zorder=None, **kwargs):
         zorder = _get_highest_zorder(axes) + 1
     _set_defaults(h, kwargs, ['common', 'line', 'fill'])
     kwargs_proxy = kwargs.copy()
-    fill = kwargs.pop('fill', False) or 'hatch' in kwargs
+    fill = kwargs.pop('fill', False) or ('hatch' in kwargs)
     if fill:
         # draw the fill without the edge
         if bottom is None:
@@ -282,7 +283,8 @@ def _hist(h, axes=None, bottom=None, logy=None, zorder=None, **kwargs):
                      zorder=zorder)
     # draw the edge
     step(h, axes=axes, logy=logy, label=None,
-         zorder=zorder + 1, alpha=kwargs['alpha'])
+         zorder=zorder + 1, alpha=kwargs['alpha'],
+         color=kwargs.get('color'))
     # draw the legend proxy
     if getattr(h, 'legendstyle', '').upper() == 'F':
         proxy = plt.Rectangle((0, 0), 0, 0, **kwargs_proxy)
@@ -626,7 +628,7 @@ def step(h, logy=None, axes=None, **kwargs):
     if logy is None:
         logy = axes.get_yscale() == 'log'
     _set_defaults(h, kwargs, ['common', 'line'])
-    if 'color' not in kwargs:
+    if kwargs.get('color') is None:
         kwargs['color'] = h.GetLineColor('mpl')
     y = np.array(list(h.y()) + [0.])
     if logy:


Test patch: