matplotlib / matplotlib/mplfinance
Date mismatch when using external axes object
Nobody has claimed this yet.
- 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()`

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:

Am I doing something wrong? Thank you
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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