Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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

    General Code/Help
    2
    4
    667
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      panda0824 last edited by

      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

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • P
          panda0824 last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

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

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors