For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Plot slicing image with custom indicator in master frame cause unexpected result



  • I have developed a custom indicator which is plotted in master frame. In order to reduce the size of saved image, I added start and end parameters in plot function like this: plot(plotter=myPlotter, start=startbar, end=endbar). However, I found sometimes the image will be compressed in y axis since the value of my indicator may larger than the maximum value between startbar and endbar. I'm sure not if there is any easy solution to fix, if yes, please let me know, thanks.
    I made a quick fix in plot.py, updated drawtag as following:

    def drawtag(self, ax, x, y, facecolor, edgecolor, alpha=0.9, **kwargs):
        label = y
        ylim = ax.get_ylim()
        if y > ylim[1]:
            y = ylim[1]
        txt = ax.text(x, y, '%.2f' % label, va='center', ha='left',
                      fontsize=self.pinf.sch.subtxtsize,
                      bbox=dict(boxstyle=tag_box_style,
                                facecolor=facecolor,
                                edgecolor=edgecolor,
                                alpha=alpha),
                      # 3.0 is the minimum default for text
                      zorder=self.pinf.zorder[ax] + 3.0,
                      **kwargs)
    

    This will fix my problem but I'm sure there should be better solutions. I'm new to backtrader and python. This is my plotted image before the fix.0_1533566732003_000603.png


  • administrators

    Not sure if the image matches your description, given that there is no indicator plotted along the data.

    The thing is, that everything that gets plotted on an axis contributes to the size of the y-scale. If your indicator goes far away from data, you may want to plot it independently with subplot=True and it won't then distort the scaling of the data.



  • Yes, the image matches my problem, as you can see the label 21.28 is far away from the top. subplot=True will plot everything in a new frame, this is not what I wanted in this case. I hope everything is plotted on the K lines, and this is always good if I don't use start and end parameters in plot function.


  • administrators

    That 21.28 is not easy to spot if not looking for it ... now the situation is clear.