Lumiwealth / quantstats_lumi

Apache License 2.0
74 stars 22 forks source link

monthly_heatmap_detailedview function spine object has no attribute "get_color" #51

Open BlackArbsCEO opened 1 month ago

BlackArbsCEO commented 1 month ago

I'm attempting to use the new function qs.plots.monthly_returns_detailedview() and it's generating an error.


Python implementation: CPython
Python version       : 3.11.9
IPython version      : 8.25.0

numpy          : 1.26.4
matplotlib     : 3.8.4
seaborn        : 0.13.2
quantstats_lumi: 0.3.3
pandas         : 2.2.2

Compiler    : MSC v.1938 64 bit (AMD64)
OS          : Windows
Release     : 10
Machine     : AMD64
Processor   : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
CPU cores   : 12
Architecture: 64bit

### code ### 
# --------------

qs.plots.monthly_returns_detailedview(equity_df)
# equity_df is a pandas series with datetime index and price values from 2008-2024. 

### error ###
# -------------
C:\Users\kngka\miniconda3\envs\blk_ml_strats\Lib\site-packages\numpy\core\_methods.py:53: RuntimeWarning:

invalid value encountered in reduce

C:\Users\kngka\miniconda3\envs\blk_ml_strats\Lib\site-packages\matplotlib\colors.py:1371: RuntimeWarning:

invalid value encountered in divide

Traceback (most recent call last):
  File "D:\PERSONAL\CODE_PROJECTS\blk_ml_strats\blk_ml\evaluate_treasury_momo_strat.py", line 46, in <module>
    qs.plots.monthly_returns_detailedview(equity_df)
  File "C:\Users\kngka\miniconda3\envs\blk_ml_strats\Lib\site-packages\quantstats_lumi\_plotting\wrappers.py", line 1093, in monthly_returns_detailedview
    fig = _core.monthly_heatmap_detailedview(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kngka\miniconda3\envs\blk_ml_strats\Lib\site-packages\quantstats_lumi\_plotting\core.py", line 1266, in monthly_heatmap_detailedview
    return_color = cell.get_color()
                   ^^^^^^^^^^^^^^
AttributeError: 'Spine' object has no attribute 'get_color'. Did you mean: 'set_color'?
grzesir commented 1 month ago

@twkim112 any ideas what this could be? I believe you changed this code recently

twkim112 commented 1 month ago
Python version: 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:34:54) [Clang 16.0.6 ]

numpy          : 2.0.0
matplotlib     : 3.9.1
seaborn        : 0.13.2
pandas         : 2.2.2
quantstats_lumi: 0.3.1

I think I've found the source of the problem. When I call qs._plotting.core.monthly_heatmap_detailedview directly with the same data used in monthly_returns_detailedview, it works without errors. Here's what I observed:

>>> cell.get_color
Out[6]: <bound method Text.get_color of Text(8.5, 0.5, '349615008342768344328711938750155849728.00')>

>>> cell.get_color()
Out[7]: '.15'

I found bugs in wrapper function. I'll work on fixing this today. @BlackArbsCEO Could you please try calling qs._plotting.core.monthly_heatmap_detailedview directly with the same data you used in monthly_returns_detailedview? This might help us isolate the issue.

twkim112 commented 1 month ago

I created PR about wrapper function.

52

BlackArbsCEO commented 1 month ago
Python version: 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:34:54) [Clang 16.0.6 ]

numpy          : 2.0.0
matplotlib     : 3.9.1
seaborn        : 0.13.2
pandas         : 2.2.2
quantstats_lumi: 0.3.1

I think I've found the source of the problem. When I call qs._plotting.core.monthly_heatmap_detailedview directly with the same data used in monthly_returns_detailedview, it works without errors. Here's what I observed:

>>> cell.get_color
Out[6]: <bound method Text.get_color of Text(8.5, 0.5, '349615008342768344328711938750155849728.00')>

>>> cell.get_color()
Out[7]: '.15'

I found bugs in wrapper function. I'll work on fixing this today. @BlackArbsCEO Could you please try calling qs._plotting.core.monthly_heatmap_detailedview directly with the same data you used in monthly_returns_detailedview? This might help us isolate the issue.

I tried your suggestion and it did work correctly when I used qs._plotting.core.monthly_heatmap_detailedview directly.

grzesir commented 1 month ago

Merged the PR. Will deploy this in future versions

Robert Grzesik 347-635-3416

On Tue, Jul 23, 2024 at 12:20 AM Taewan Kim @.***> wrote:

I created PR about wrapper function.

— Reply to this email directly, view it on GitHub https://github.com/Lumiwealth/quantstats_lumi/issues/51#issuecomment-2244221878, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIYQK5J2WKIK6M2KC5L6ETZNXKY3AVCNFSM6AAAAABLIPNWGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBUGIZDCOBXHA . You are receiving this because you commented.Message ID: @.***>