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

Update _settings.py for Seaborn #552

Merged
merged 1 commit into from
Jan 21, 2023
Merged

Update _settings.py for Seaborn #552

merged 1 commit into from
Jan 21, 2023

Conversation

Kalindro
Copy link
Contributor

Hi!

What?

I changed Seaborn theme colors format to HEX format (as in other themes) from RGB format.

Why?

While using Seaborn, plotting fails for many default graphs, mainly from portfolio.plot().

Comment

Is there any reason why color settings for Seaborn theme are in RGB instead of HEX?
In PR I just changed the colors to same format as in other themes, if there is a reason - there may be a better fix, but this works in my environment after the change, fails with default.

Error:

  File "D:\Google Drive Sync\Rzeczy\Projekty_PY\Boty\CyberOasisProjectReborn\gieldy\vectorbt\main.py", line 67, in backtest_keltner
    fig = pf.plot(subplots=[
  File "D:\Google Drive Sync\Rzeczy\Projekty_PY\.venvs\Crypto-Venv-3-10-0\lib\site-packages\vectorbt\generic\plots_builder.py", line 604, in plots
    raise e
  File "D:\Google Drive Sync\Rzeczy\Projekty_PY\.venvs\Crypto-Venv-3-10-0\lib\site-packages\vectorbt\generic\plots_builder.py", line 589, in plots
    plot_func(**final_kwargs)
  File "D:\Google Drive Sync\Rzeczy\Projekty_PY\.venvs\Crypto-Venv-3-10-0\lib\site-packages\vectorbt\portfolio\base.py", line 4940, in plot_assets
    fillcolor=adjust_opacity(plotting_cfg['color_schema']['brown'], 0.3)
  File "D:\Google Drive Sync\Rzeczy\Projekty_PY\.venvs\Crypto-Venv-3-10-0\lib\site-packages\vectorbt\utils\colors.py", line 27, in adjust_opacity
    rgb = mc.to_rgb(color)
  File "D:\Google Drive Sync\Rzeczy\Projekty_PY\.venvs\Crypto-Venv-3-10-0\lib\site-packages\matplotlib\colors.py", line 496, in to_rgb
    return to_rgba(c)[:3]
  File "D:\Google Drive Sync\Rzeczy\Projekty_PY\.venvs\Crypto-Venv-3-10-0\lib\site-packages\matplotlib\colors.py", line 299, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
  File "D:\Google Drive Sync\Rzeczy\Projekty_PY\.venvs\Crypto-Venv-3-10-0\lib\site-packages\matplotlib\colors.py", line 374, in _to_rgba_no_colorcycle
    raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
ValueError: Invalid RGBA argument: 'rgb(204,185,116)'

Process finished with exit code 1

On:

pf.plot(subplots=[
            "drawdowns"])

Because of:

kwargs = merge_dicts(dict(
            trace_kwargs=dict(
                line=dict(
                    color=plotting_cfg['color_schema']['brown']
                ),
                name='Assets'
            ),
            pos_trace_kwargs=dict(
                fillcolor=adjust_opacity(plotting_cfg['color_schema']['brown'], 0.3)
            ),
            neg_trace_kwargs=dict(
                fillcolor=adjust_opacity(plotting_cfg['color_schema']['orange'], 0.3)
            ),
            other_trace_kwargs='hidden'

Where adjust_opacity takes color in HEX format and fails on this RGB format from Seaborn:

def adjust_opacity(color: tp.Any, opacity: float) -> str:
    """Adjust opacity of color."""
    import matplotlib.colors as mc
    print(color)
    rgb = mc.to_rgb(color)
    print(rgb)
    return 'rgba(%d,%d,%d,%.4f)' % (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255), opacity)

@polakowo
Copy link
Owner

polakowo commented Jan 21, 2023

That's a limitation of adjust_opacity, there should be additional tests for rgb and rgba values like in the pro version. I'll merge your PR since this is an easier fix. Thank you!

@polakowo polakowo merged commit 781c01f into polakowo:master Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants