matplotlib / matplotlib/mplfinance

What is the most elegant way to implement ribbons?

Open
#668 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
4.4k
Forks
678
PR merge metrics
No merged PRs in 30d

Description

I am currently thinking about the most elegant way to display 1-2 scatter lines below the chart.
Are there any ideas from others who have already implemented this?

These are my first ideas:
![image](https://github.com/matplotlib/mplfinance/assets/49436733/f978361c-0a13-49fc-9e7a-b2630e099b2d)

```
import mplfinance as mpf

output = sp_500 ['2021-01-01':].copy()

output["sma_above"] = np.where (output.Close > output.sma, output.sma, np.nan)
output["sma_below"] = np.where (output.Close < output.sma, output.sma, np.nan)

output["ribbon_above"] = np.where (output.Close > output.sma, 1, np.nan)
output["ribbon_below"] = np.where (output.Close < output.sma, 1, np.nan)

add_plt = [
mpf.make_addplot(output["sma_above"],color="green"),
mpf.make_addplot(output["sma_below"],color="red"),
mpf.make_addplot(output["ribbon_above"], panel=1, color="g", type='scatter'),
mpf.make_addplot(output["ribbon_below"], panel=1, color="r", type='scatter'),
]

mpf.plot(
output,
addplot=add_plt,
figsize=(16, 9),
style="charles",
type="candle",
title='S&P 500 - weekly',
datetime_format='%d.%m.%y',xrotation=45,
)
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the issue's example calls to mpf.make_addplot and mpf.plot, including the separate panel and scatter settings. The issue does not name files or tests, so the first step is to locate those entry points and determine the intended ribbon API. Done would require an agreed design and a working way to display ribbons below the chart.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, python
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.