Skip to content

Use matplotlib object-oriented API for plotting #482

@israelmcmc

Description

@israelmcmc

There are multiple functions in cosipy using pyplot directly e.g. plt.plot() --i.e. the stateful interface. This is OK for an user-defined or user-facing script, but not in a library, since it makes it hard to control the flow and can conflict with the user customization. See for example the issue described in #481.

Instead, all methods generating a plot should take as input a matplotlib Axes, which will be the one use to produce the plot. The user would do seomething like

# Create Axes
fig,ax = plt.subplot()

# Plot using cosipy
foo.plot(ax)

# Customize
ax.set_xlim(5,10)

Internally, the plotting function should look like:

def plot(ax = None):

    if ax is None:
        # Create Axes it not provided
        fig,ax = plt.subplots()

    x,y = compute_data() 
    ax.plot(x,y)

    return ax

See also histpy and mhealpy for more examples.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions