Skip to content

Correct colour norm for permeation regimes tutorial #98

@RemDelaporteMathurin

Description

@RemDelaporteMathurin
class MidPointLogNorm(mcolors.LogNorm):
    def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
        mcolors.LogNorm.__init__(self,vmin=vmin, vmax=vmax, clip=clip)
        self.midpoint=midpoint
    def __call__(self, value, clip=None):
        result, is_scalar = self.process_value(value)
        x, y = [np.log(self.vmin), np.log(self.midpoint), np.log(self.vmax)], [0, 0.5, 1]
        return np.ma.array(np.interp(np.log(value), x, y), mask=result.mask, copy=False)


# norm = mcolors.SymLogNorm(linthresh=permeation_number(pressures[0]), vmin=permeation_number(pressures[0]), vmax=permeation_number(pressures[-1]))
norm = MidPointLogNorm(vmin=permeation_number(pressures[0]), midpoint=1, vmax=permeation_number(pressures[-1]))
cmap = plt.cm.RdYlGn

Issue: for some reason making the colourbar with:

sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)

plt.colorbar(
    sm,
    label="Permeation number",
    ax=plt.gca(),
)

Doesn't generate the right colourbar.... (the center is not on 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions