html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/500#issuecomment-126532498,https://api.github.com/repos/pydata/xarray/issues/500,126532498,MDEyOklzc3VlQ29tbWVudDEyNjUzMjQ5OA==,1217238,2015-07-31T00:52:38Z,2015-07-31T00:52:38Z,MEMBER,"Yeah, I guess we would only want a legend if we're truly plotting categorical values (e.g., from pandas.cut)

On Thu, Jul 30, 2015 at 5:31 PM, Clark Fitzgerald
notifications@github.com wrote:

> ## The legend definitely looks better than the color bar in the seaborn PR.
> 
> Reply to this email directly or view it on GitHub:
> https://github.com/xray/xray/issues/500#issuecomment-126530340
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,97861940
https://github.com/pydata/xarray/issues/500#issuecomment-126530340,https://api.github.com/repos/pydata/xarray/issues/500,126530340,MDEyOklzc3VlQ29tbWVudDEyNjUzMDM0MA==,5356122,2015-07-31T00:31:37Z,2015-07-31T00:31:37Z,MEMBER,"The legend definitely looks better than the color bar in the seaborn PR.
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,97861940
https://github.com/pydata/xarray/issues/500#issuecomment-126527616,https://api.github.com/repos/pydata/xarray/issues/500,126527616,MDEyOklzc3VlQ29tbWVudDEyNjUyNzYxNg==,1217238,2015-07-31T00:18:29Z,2015-07-31T00:18:38Z,MEMBER,"Also worth taking a look at for possible API and/or code inspiration:
https://github.com/mwaskom/seaborn/pull/629

Do we want a color bar or a legend for discrete colormaps?
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,97861940
https://github.com/pydata/xarray/issues/500#issuecomment-126470540,https://api.github.com/repos/pydata/xarray/issues/500,126470540,MDEyOklzc3VlQ29tbWVudDEyNjQ3MDU0MA==,1217238,2015-07-30T20:22:00Z,2015-07-30T20:22:00Z,MEMBER,"Instead of adding a separate argument `cmap_intervals`, it might make sense to call the argument `levels` -- which is the name of the existing `contour`/`contourf` argument. Then, it could work consistently between imshow/pcolormesh/contour/contourf.
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,97861940
https://github.com/pydata/xarray/issues/500#issuecomment-126447673,https://api.github.com/repos/pydata/xarray/issues/500,126447673,MDEyOklzc3VlQ29tbWVudDEyNjQ0NzY3Mw==,1217238,2015-07-30T19:29:27Z,2015-07-30T19:29:27Z,MEMBER,"@jhamman take a look at pandas.cut: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.cut.html
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,97861940
https://github.com/pydata/xarray/issues/500#issuecomment-126445362,https://api.github.com/repos/pydata/xarray/issues/500,126445362,MDEyOklzc3VlQ29tbWVudDEyNjQ0NTM2Mg==,2443309,2015-07-30T19:24:33Z,2015-07-30T19:24:33Z,MEMBER,"I have this mostly working on my branch now.  A few questions before I issue a PR.

@clarkfitzg - do you happen to have any example code that creates intervals from a list?  I also think it would be better to only use ticks defined by the user, so your case would need to be: `myarray.plot_imshow(cmap_intervals=[-np.inf, -1, 1, np.inf])`.
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,97861940
https://github.com/pydata/xarray/issues/500#issuecomment-126012923,https://api.github.com/repos/pydata/xarray/issues/500,126012923,MDEyOklzc3VlQ29tbWVudDEyNjAxMjkyMw==,5356122,2015-07-29T16:41:40Z,2015-07-29T16:41:40Z,MEMBER,"So the user would write something like `myarray.plot_imshow(cmap_intervals=5)` and see the colors discretized into 5 bins? Sounds nice.

We could also allow a sequence for `cmap_intervals` so that `myarray.plot_imshow(cmap_intervals=[-1, 1])` uses three bins: (-inf, -1], (-1, 1], (1, inf)
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,97861940
https://github.com/pydata/xarray/issues/500#issuecomment-125974756,https://api.github.com/repos/pydata/xarray/issues/500,125974756,MDEyOklzc3VlQ29tbWVudDEyNTk3NDc1Ng==,2443309,2015-07-29T14:45:51Z,2015-07-29T14:45:51Z,MEMBER,"Exactly.

I've used something like this to generate the discrete colormap:

``` python
def cmap_discretize(cmap, n_colors):
    """"""Return a discrete colormap from the continuous colormap cmap.

    Parameters
    ----------
    cmap : str or colormap object
        Colormap to discretize.
    n_colors : int
        Number of discrete colors to divide `cmap` into.

    Returns
    ----------
    discrete_cmap : LinearSegmentedColormap
        Discretized colormap.
    """"""
    from matplotlib.colors import LinearSegmentedColormap
    import matplotlib.pyplot as plt

    if type(cmap) == basestring:
        cmap = plt.get_cmap(cmap)
    colors_i = np.concatenate((np.linspace(0, 1., n_colors), (0., 0., 0., 0.)))
    colors_rgba = cmap(colors_i)
    indices = np.linspace(0, 1., n_colors + 1)
    cdict = {}
    for ki, key in enumerate(('red', 'green', 'blue')):
        cdict[key] = [(indices[i], colors_rgba[i - 1, ki], colors_rgba[i, ki])
                      for i in range(n_colors + 1)]
    # Return colormap object.
    return LinearSegmentedColormap(cmap.name + ""_%d"" % n_colors, cdict, 1024)
```

Typically, I've manually constructed the colorbar by hand with the discrete colormap:

``` python
cmap = cmap_discretize(cmap, n_colors=10)
cnorm = mpl.colors.Normalize(vmin=vmin, vmax=vmax)
cticks = np.linspace(vmin, vmax, num=cn + 1)

cb = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=cnorm,
                               orientation='vertical',
                               extend=cbar_extend,
                               ticks=cticks)
```

I'm sure this later part can be improved.  Possibly by using [`matplotlib.ticker.MaxNLocator`](http://matplotlib.org/api/ticker_api.html#matplotlib.ticker.MaxNLocator) to find/set the ticks and intervals.
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,97861940
https://github.com/pydata/xarray/issues/500#issuecomment-125849396,https://api.github.com/repos/pydata/xarray/issues/500,125849396,MDEyOklzc3VlQ29tbWVudDEyNTg0OTM5Ng==,1217238,2015-07-29T05:41:03Z,2015-07-29T05:41:03Z,MEMBER,"This is also something I often find useful, so +1 from me. `contourf` does something similar, but it also involves plotting contour lines.
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,97861940