Repository: scikit-hep/hist

Issue:
[FEATURE] kw dict
Consider adding a dict for each sub-axis to control options to it, in addition to (for now) the prefixing.


Discussion:
sourcery-ai[bot]: # Sourcery Code Quality Report


✅ &nbsp;Merging this PR will **increase** code quality in the affected files by **0.09%**.

| Quality metrics | Before | After | Change |
| --- | :---: | :---: | :---: |
| [Complexity](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#complexity) | 5.31 ⭐ | 5.30 ⭐ | -0.01 👍 |
| [Method Length](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#method-length) | 137.32 😞 | 138.41 😞 | 1.09 👎 |
| [Working memory](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#working-memory) | 17.34 ⛔ | 17.30 ⛔ | -0.04 👍 |
| **[Quality](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#quality-score)** | **46.58%** 😞| **46.67%** 😞| **0.09%** 👍 |



| Other metrics | Before | After | Change |
| --- | :---: | :---: | :---: |
| Lines | 1400 | 1420 | 20 |



| Changed files | Quality Before | Quality After | Quality Change |
| --- | :---: | :---: | :---: |
| src/hist/plot.py | 43.57% 😞 | 43.84% 😞 | 0.27% 👍|
| tests/test_plot.py | 50.26% 🙂 | 50.15% 🙂 | -0.11% 👎|



Here are some functions in these files that still need a tune-up:

| File | Function | Complexity | Length | Working Memory | Quality | Recommendation |
| --- | --- | :---: | :---: | :---: | :---: | --- |
| src/hist/plot.py | \_plot\_ratiolike | 27 😞 | 523 ⛔ | 29 ⛔ | 12.43% ⛔ | Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions |
| src/hist/plot.py | plot\_ratio\_array | 3 ⭐ | 334 ⛔ | 26 ⛔ | 34.49% 😞 | Try splitting into smaller methods. Extract out complex expressions |
| src/hist/plot.py | plot2d\_full | 9 🙂 | 278 ⛔ | 14 😞 | 38.61% 😞 | Try splitting into smaller methods. Extract out complex expressions |
| tests/test_plot.py | test\_general\_plot1d.test\_general\_plot2d.test\_general\_plot2d\_full.test\_general\_plot.test\_general\_plot\_pull | 0 ⭐ | 361 ⛔ | 16 ⛔ | 42.67% 😞 | Try splitting into smaller methods. Extract out complex expressions |
| tests/test_plot.py | test\_general\_plot1d.test\_general\_plot2d.test\_general\_plot2d\_full.test\_general\_plot.test\_named\_plot1d.test\_named\_plot2d.test\_named\_plot2d\_full.test\_named\_plot.test\_named\_plot\_pull | 0 ⭐ | 357 ⛔ | 16 ⛔ | 42.75% 😞 | Try splitting into smaller methods. Extract out complex expressions |


## Legend and Explanation

The emojis denote the absolute quality of the code:

 - ⭐ excellent
 - 🙂 good
 - 😞 poor
 - ⛔ very poor


The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.

***

Please see our documentation [here](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report) for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.
sourcery-ai[bot]: # Sourcery Code Quality Report


✅ &nbsp;Merging this PR will **increase** code quality in the affected files by **0.07%**.

| Quality metrics | Before | After | Change |
| --- | :---: | :---: | :---: |
| [Complexity](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#complexity) | 5.31 ⭐ | 5.30 ⭐ | -0.01 👍 |
| [Method Length](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#method-length) | 137.32 😞 | 138.70 😞 | 1.38 👎 |
| [Working memory](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#working-memory) | 17.34 ⛔ | 17.30 ⛔ | -0.04 👍 |
| **[Quality](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#quality-score)** | **46.58%** 😞| **46.65%** 😞| **0.07%** 👍 |



| Other metrics | Before | After | Change |
| --- | :---: | :---: | :---: |
| Lines | 1400 | 1420 | 20 |



| Changed files | Quality Before | Quality After | Quality Change |
| --- | :---: | :---: | :---: |
| src/hist/plot.py | 43.57% 😞 | 43.81% 😞 | 0.24% 👍|
| tests/test_plot.py | 50.26% 🙂 | 50.15% 🙂 | -0.11% 👎|



Here are some functions in these files that still need a tune-up:

| File | Function | Complexity | Length | Working Memory | Quality | Recommendation |
| --- | --- | :---: | :---: | :---: | :---: | --- |
| src/hist/plot.py | \_plot\_ratiolike | 27 😞 | 523 ⛔ | 29 ⛔ | 12.43% ⛔ | Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions |
| src/hist/plot.py | plot\_ratio\_array | 3 ⭐ | 334 ⛔ | 26 ⛔ | 34.49% 😞 | Try splitting into smaller methods. Extract out complex expressions |
| src/hist/plot.py | plot2d\_full | 9 🙂 | 278 ⛔ | 14 😞 | 38.61% 😞 | Try splitting into smaller methods. Extract out complex expressions |
| tests/test_plot.py | test\_general\_plot1d.test\_general\_plot2d.test\_general\_plot2d\_full.test\_general\_plot.test\_general\_plot\_pull | 0 ⭐ | 361 ⛔ | 16 ⛔ | 42.67% 😞 | Try splitting into smaller methods. Extract out complex expressions |
| tests/test_plot.py | test\_general\_plot1d.test\_general\_plot2d.test\_general\_plot2d\_full.test\_general\_plot.test\_named\_plot1d.test\_named\_plot2d.test\_named\_plot2d\_full.test\_named\_plot.test\_named\_plot\_pull | 0 ⭐ | 357 ⛔ | 16 ⛔ | 42.75% 😞 | Try splitting into smaller methods. Extract out complex expressions |


## Legend and Explanation

The emojis denote the absolute quality of the code:

 - ⭐ excellent
 - 🙂 good
 - 😞 poor
 - ⛔ very poor


The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.

***

Please see our documentation [here](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report) for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

Patch:
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 671e9b9..541af9a 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -25,6 +25,9 @@ IN PROGRESS
 * Add ``fit_fmt=`` to ``plot_pull`` to control display of fit params.
   `#168 <https://github.com/scikit-hep/hist/pull/168>`_
 
+* Support ``<prefix>_kw`` arguments for setting each axis in plotting.
+  `#193 <https://github.com/scikit-hep/hist/pull/193>`_
+
 * Cleaner IPython completion for Python 3.7+.
   `#179 <https://github.com/scikit-hep/hist/pull/179>`_
 
diff --git a/src/hist/plot.py b/src/hist/plot.py
index d69d135..8020038 100644
--- a/src/hist/plot.py
+++ b/src/hist/plot.py
@@ -82,16 +82,22 @@ def _expand_shortcuts(key: str) -> str:
 
 
 def _filter_dict(
-    dict: Dict[str, Any], prefix: str, *, ignore: Optional[Set[str]] = None
+    __dict: Dict[str, Any], prefix: str, *, ignore: Optional[Set[str]] = None
 ) -> Dict[str, Any]:
     """
     Keyword argument conversion: convert the kwargs to several independent args, pulling
-    them out of the dict given.
+    them out of the dict given. Prioritize prefix_kw dict.
     """
+
+    # If passed explicitly, use that
+    if f"{prefix}kw" in __dict:
+        res: Dict[str, Any] = __dict.pop(f"{prefix}kw")
+        return {_expand_shortcuts(k): v for k, v in res.items()}
+
     ignore_set: Set[str] = ignore or set()
     return {
-        _expand_shortcuts(key[len(prefix) :]): dict.pop(key)
-        for key in list(dict)
+        _expand_shortcuts(key[len(prefix) :]): __dict.pop(key)
+        for key in list(__dict)
         if key.startswith(prefix) and key not in ignore_set
     }
 


Test patch:
diff --git a/tests/test_plot.py b/tests/test_plot.py
index 5a4d356..a05c61c 100644
--- a/tests/test_plot.py
+++ b/tests/test_plot.py
@@ -108,6 +108,20 @@ def test_general_plot2d_full():
         side_color="steelblue",
     )
 
+    assert h.plot2d_full(
+        main_cmap="cividis",
+        top_kw={
+            "ls": "--",
+            "color": "orange",
+            "lw": 2,
+        },
+        side_kw={
+            "ls": "-.",
+            "lw": 1,
+            "color": "steelblue",
+        },
+    )
+
     # dimension error
     h = Hist(
         axis.Regular(