earmingol/cell2cell

Improve matplotlib-based code for compatibility with newer versions

Closed this issue · 0 comments

Implement better ways of generating plots, which are also compatible with newer versions of matplotlib.

For example, for legends in cell2cell.plotting.aesthetics use something like this:

def generate_legend(color_dict, loc='center left', bbox_to_anchor=(1.01, 0.5), ncol=1, fancybox=True, shadow=True,
                    title='Legend', fontsize=14, sorted_labels=True, ax=None):
    color_patches = []
    if sorted_labels:
        iteritems = sorted(color_dict.items())
    else:
        iteritems = color_dict.items()
    for k, v in iteritems:
        color_patches.append(patches.Patch(color=v, label=str(k).replace('_', ' ')))

    if ax is None:
        ax = plt.gca()

    legend1 = ax.legend(handles=color_patches,
                        loc=loc,
                        bbox_to_anchor=bbox_to_anchor,
                        ncol=ncol,
                        fancybox=fancybox,
                        shadow=shadow,
                        title=title,
                        fontsize=fontsize)

    legend1.set_title(title, fontsize=fontsize)
    ax.add_artist(legend1)

    return legend1