matplotlib / matplotlib/mplfinance

Date mismatch when using external axes object

Open
#364 11 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 have the following dataframe that contains ohlc data:
`candles.head()`
![issue](https://user-images.githubusercontent.com/48249882/111898609-7cf94280-8a27-11eb-9a73-a8c77237575a.png)
I want to plot the data using an external axes object and then add additional stuff on the chart using matplotlib. The problem is that there seems to be a mismatch in the way mplfinance and matplotlib handle dates. For example, the following code:
```python
fig = mpf.figure(style='yahoo')
ax = fig.add_subplot(1,1,1)

mpf.plot(candles, ax=ax)

ax.plot(candles.index, candles.open)
```
should overlay a line connecting all the opens of the candles. However, the result is this:
![issue2](https://user-images.githubusercontent.com/48249882/111898954-85527d00-8a29-11eb-919e-ab303d72cae5.png)
Am I doing something wrong? Thank you

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 with the external-axes example using mpf.plot(candles, ax=ax) followed by ax.plot(candles.index, candles.open), and trace how each call handles the dataframe's dates. Reproduce the mismatch with the supplied example; done means the additional line overlays the corresponding candles without requiring callers to manually convert dates.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.