Histogram argument not inherited when using global dictionary parameters
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 576
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
Description of the issue
When using a global dictionary for key-worded arguments in corner.corner(), the method will not take into account new parameters (for color for instance) if it already exists in a global instance passed as a parameter to hist_kwargs.
This is because hist_kwargs is written on the parameter passed, not on a copied instance. Therefore, some of its argument may already exist if it was modified during a previous corner.corner call, typically in a loop.
Steps to reproduce
Here is a minimal code reproducing to issue:
import corner
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
corner_kwargs = dict(
fig=fig,
show_titles=True,
plot_contours=True,
fill_contours=False,
plot_density=False,
plot_datapoints=False,
title_fmt=".2f",
hist_kwargs={"density": True}, # HERE
label_kwargs={"fontsize": 18},
linewidths = 1.5,
alpha=0.5
)
colors = ["r", "g", "b"]
ndim, nsamples = 2, 10000
for color in colors:
samples = np.random.randn(ndim * nsamples).reshape([nsamples, ndim])
corner.corner(samples, color=color,
# hist_kwargs={"density": True}, # HERE
**corner_kwargs)
Expected behavior
One would expect the color to change at each iteration for the histogram, but it doesn't (although correlation plots are not affected).
Workaround
To bypass this issue, one can define a new dictionary instance to pass at each iteration, such as in the commented line #HERE above.
However this prevents from creating clean common parameter dictionary when working with a large number of common arguments.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the corner.corner() entry point and trace how hist_kwargs is handled across repeated calls using the reproduction example. Ensure the shared dictionary is not modified between calls, then rerun the loop to verify that each histogram uses the current color while correlation plots remain unaffected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, numpy, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100