mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

How can i avoid candles compression when placing horizontal lines?

Open Jacks349 opened this issue 4 years ago • 2 comments

I've been using MPL finance for quite some time now, everything is flawless and i'm impressed by the new features! I'm trying to fix a problem that has to do with Matplotlib itself too: once i add to my chart two horizontal lines that are far from the last price, the candles will get compressed and the chart becomes harder to read. Now i know that this happens because of the horizontal lines, but i was wondering if there is some way/method/function to scale the chart so that the candles stay less compressed while keeping the lines. Thanks in advance!

fig, axlist = mpf.plot(df, type='candle', figscale=2, figratio=(50, 50), style=s, returnfig=True)
ax1 = axlist[0]
ax1.axhline(8000)
ax1.axhline(14000)

q

Jacks349 avatar Oct 03 '20 22:10 Jacks349

I can think of a few things to try but I am unsure if they will actually help much:

  • make the plot larger (I see you already have figscale=2; you might try a 3 or 4)
  • depending which matplotlib backend you are using, the candles will probably still look small on the initial plot, but you may have the ability to zoom in (if you use a backend that has a built-in zoom widget).
    • Also, some backends may respond better to increasing figscale than others, placing a much larger plot on your screen; and the size and resolution of your monitor may make a difference as well).
  • you might try a logarithmic scale on the price axis.
  • the horizontal lines could be put on a secondary_y axis (but I'm guessing this may defeat the purpose you have at wanting those horizontal lines).

If you can explain exactly what goal you are trying to accomplish by having horizontal lines so far away from the maximum and minimum values in your pricing stream, then I may be able to think of other ways to achieve the same goal.

DanielGoldfarb avatar Oct 05 '20 01:10 DanielGoldfarb

Thank you alot! I'm going to try what you suggested, i think using a logarithmic scale could help. As for what i'm trying to accomplish, these lines are ordinary support and resistance levels that i'm generating dynamically, so they are applied to the chart and then the chart is saved.

I was trying to do the following: scale only the zones of the chart where there will be lines but not the zone where there are candles. So this means that in the zone where there are candles, the distance between each price point, on the price axis, stays the same, but above and below the candles, where i'll put the lines, the distance between price points will be less. I don't know if it's doable though.

Jacks349 avatar Oct 05 '20 07:10 Jacks349