matplotlib / matplotlib/mplfinance

Skip empty dataframes when creating addplots

Open
#103 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I add signals to my diagram using `make_addplot`. But if there are no signals in the selected time period, I get an error.

I have solved it for me as follows:

```
if stock[stock['Signal'].notnull()].shape[0] == 0:
print ("- no Signal")
else:
signal_short = mpf.make_addplot(stock['Signal'] * 0.93,
scatter=True,
markersize=150,
marker='v',
color='red'
)
add_plots.append(signal_short)
```

Would it not be an option to integrate this directly into the function and, if necessary, only issue a warning?

```
if data.notnull()].shape[0] == 0:
raise Warning("Empty Dataframe!")
```

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 at the make_addplot entry point and reproduce the issue with an empty Signal series in the selected time period. Trace how the resulting addplot is handled, then verify that empty data is skipped or reported without raising the current error. Done means the supplied no-signal case completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, python
Domain
data-visualization
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.