Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type='HLC' for classic western style HLC Bar chart #334

Open
anhiliate opened this issue Feb 15, 2021 · 9 comments
Open

type='HLC' for classic western style HLC Bar chart #334

anhiliate opened this issue Feb 15, 2021 · 9 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@anhiliate
Copy link

Hi everyone,
I am using the original flavor of mplfinance and I am really struggling creating a simple HLC bar chart as below.
Does someone have an idea how this could be achieved?

charts-4sunw-hlc

When I fill the Open column with Close data, I will get the chart but lose the coloring. I hope I don't have to split up the date based on Open< Close and Open>Close and then draw 2 candlesticks, do I?
Thank you all in advance for the help.

@anhiliate anhiliate added the question Further information is requested label Feb 15, 2021
@anhiliate anhiliate changed the title How to draw a classic western style How to draw a classic western style HLC Bar chart Feb 15, 2021
@DanielGoldfarb
Copy link
Collaborator

@anhiliate
just curious to know why you closed this? Did you figure out a way to do it? (If so, why not post your solution here for others).

i was just thinking this might be a nice additional to the new mplfinance as kwarg type='HLC'.

@anhiliate
Copy link
Author

Hi Daniel,

thank you for the prompt response and for taking care of this awesome project.
I was just impatient and since I'm a python noob, I ended up being satisfied with the new mplfinance in standard mode, which does a very fine job already.
The only missing thing for me were only:

  • the HLC,
  • possiblity to include subplots using gridspec (because MACD or RSI or other benchmark might be useful)
  • Easy way for date format like above (or like IBD chart with week/month date/year begin)

You definitely have my vote for kwarg type='HLC'.
Please let me know if the ticket should be reopened.

@DanielGoldfarb
Copy link
Collaborator

Thanks.
Regarding gridspec, there is a workaround, but no direct method.

Have you read through this tutorial on creating subplot panels? Please do, and let me know if it suits your needs. If after working through that tutorial you still feel you need gridspec please explain why so that I can understand what's missing from the package.

Regarding the date format, we did get a similar request here; and I am considering whether to implement it. In the meantime you do have some control over the date format as demonstrated in cell In [8] of the customizations tutorial.

@DanielGoldfarb DanielGoldfarb changed the title How to draw a classic western style HLC Bar chart Implement type= for classic western style HLC Bar chart Feb 16, 2021
@DanielGoldfarb DanielGoldfarb added the enhancement New feature or request label Feb 16, 2021
@DanielGoldfarb DanielGoldfarb changed the title Implement type= for classic western style HLC Bar chart Implement type='HLC' for classic western style HLC Bar chart Feb 16, 2021
@DanielGoldfarb DanielGoldfarb changed the title Implement type='HLC' for classic western style HLC Bar chart type='HLC' for classic western style HLC Bar chart Feb 16, 2021
@anhiliate
Copy link
Author

Thank you Daniel,
I went through the tutorial on creating subplot panels but I'm still stuck on one specific use case. And that is to split the last panel into 3 columns to display charts + return for alternative investments like Gold or EU or Chinese market.
With that, all panels until then will share the xaxis while the last one will have 3.
In general, I think that the option to split one specific panel into 2-3-4 columns would be really powerful (unless nobody else is messy like me and want to have everything compressed into one plot).
Regarding the thread of the IBD chart, I'm really impressed by the result, which led me to try to achieve the following format on the weekly chart.
weekly_ChartLists _ StockCharts
Well, if anyone has a code snippet for this date format, I would really be thankful :)

@DanielGoldfarb
Copy link
Collaborator

Thanks @anhiliate ... Can you provide and image similar to your the case (where the last panel is split into three columns) you want to acheive?

@anhiliate
Copy link
Author

anhiliate commented Feb 16, 2021

Hi Daniel,

of course, this is what I had in mind:
trinket_plot
And in case you allow me to be a bit choosy, I find this syntax the most readable and less error prone to get the result above, it does not allow heigh customizations like gridspec though.

import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = plt.subplot2grid((6,3), (0,0), rowspan=2, colspan=3)
ax2 = plt.subplot2grid((6,3), (2,0), colspan=3)
ax3 = plt.subplot2grid((6,3), (3,0), colspan=3)
ax4 = plt.subplot2grid((6,3), (4,0), colspan=3)
ax5 = plt.subplot2grid((6,3), (5,0))
ax5 = plt.subplot2grid((6,3), (5,1))
ax5 = plt.subplot2grid((6,3), (5,2))
plt.show()

@DanielGoldfarb
Copy link
Collaborator

Thanks. For now, the workaround would be to use external axes mode.

Although subplot2grid is not directly supported (but can be used) I would recommend instead using add_axes() as described in this answer here.

@anhiliate
Copy link
Author

Thanks Daniel,

good point, I'll try that out and update the result when I have something usable.

@anhiliate
Copy link
Author

anhiliate commented Feb 22, 2021

Sorry, it was a busy week so I only got a bit of time to play with it today.
In case someone is interested, you can easily use the external axes like Daniel has proposed to get the layout I mentioned above.
Below is the code to demonstrate it, with emphasis on easy maintenance and simple adjustment on layout changes:
`
fig = mpf.figure()

widths = [3, 3, 3]
heights = [3, 5, 2, 3, 3]

spec = gridspec.GridSpec(ncols=3, nrows=5,
width_ratios=widths,
height_ratios=heights)
ax1 = fig.add_subplot(spec[0, :])
ax1.annotate("AX1", (0.1, 0.5), xycoords='axes fraction', va='center')
ax2 = fig.add_subplot(spec[1, :])
ax2.annotate("AX2", (0.1, 0.5), xycoords='axes fraction', va='center')
ax2 = fig.add_subplot(spec[2, :])
ax2.annotate("AX3", (0.1, 0.5), xycoords='axes fraction', va='center')
ax2 = fig.add_subplot(spec[3, :])
ax2.annotate("AX4", (0.1, 0.5), xycoords='axes fraction', va='center')
ax4 = fig.add_subplot(spec[4,0: -2])
ax4.annotate("AX5", (0.1, 0.5), xycoords='axes fraction', va='center')
ax5 = fig.add_subplot(spec[4,1: -1])
ax5.annotate("AX6", (0.1, 0.5), xycoords='axes fraction', va='center')
ax5 = fig.add_subplot(spec[4,2:])
ax5.annotate("AX7", (0.1, 0.5), xycoords='axes fraction', va='center')

plt.show()
`
Figure_1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants