Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: extra keyword arguments ignored for ternary density plots (e.g. vmax) #89

Open
morganjwilliams opened this issue Aug 15, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@morganjwilliams
Copy link
Owner

morganjwilliams commented Aug 15, 2023

Describe the bug

Specifically for density plots on ternary axes, because of the introspection used by pyrolite together with how indirection/handler functions are structured within mpltern, and the fact that pyrolite uses the e.g. tripcolor variants, extra keyword arguments including vmax are not passed through to the relevant pcolor/pcolormesh functions in matplotilib

To Reproduce

import matplotlib.pyplot as plt
import numpy as np
 
import pyrolite.plot
from pyrolite.util.synthetic import normal_frame
 
# ternary random data, with a specific composition
# broad enough distribution to visualize colormapped values
df = normal_frame(
    size=1000,
    seed=11,
    columns=["SiO2", "CaO", "MgO"],
    mean=np.array([0.1, 0.4, 0.3]),
    cov=0.1 * np.array([[1.2, -0.15], [-0.15, 1.2]]),
)

ax = df.pyroplot.density(vmax=0) 

Expected behavior

Keyword arguments are passed through to the relevant pcolor/pcolormesh functions in matplotilib.

Temporary Workaround:

For at least some parameters, some attributes of e.g. the colormap and norm are able to be modified after the collection has been added to an axis; this requires a bit of reading through the properties of the collection, but makes styling changes possible, e.g.:

# set the `vmax` property of the norm from the last collection added to the axes
ax.collections[-1]._norm.vmax = 0
@morganjwilliams morganjwilliams added the bug Something isn't working label Aug 15, 2023
@morganjwilliams morganjwilliams self-assigned this Aug 15, 2023
@morganjwilliams
Copy link
Owner Author

morganjwilliams commented Aug 19, 2023

One way to patch this (in lieu of a likely future PR to mpltern adding this to the assorted axes plotting methods), is as follows, adding relevant keyword arguments to mpltern._axes.TernaryAxes.tripcolor:

from functools import wraps

import mpltern
from mpltern.ternary_parsers import _parse_ternary_single

@_parse_ternary_single
def _tripcolor(self,
    *args,
    alpha=1.0,
    norm=None,
    cmap=None,
    vmin=None,
    vmax=None,
    shading='flat',
    facecolors=None,
    **kwargs,
):
	return super(mpltern.ternary._axes.TernaryAxes, self).tripcolor(*args, 
                      alpha=alpha,
                      norm=norm,
                      cmap=cmap,
                      vmin=vmin,
                      vmax=vmax,
                      shading=shading,
                      facecolors=facecolors,
                      **kwargs,
                      )

mpltern.ternary._axes.TernaryAxes.tripcolor = _tripcolor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant