Skip to content

Trying to draw an InfiniteLine on mouse-click, but won't display #328

Answered by highfestiva
ShivaSmith asked this question in Q&A
Discussion options

You must be logged in to vote

You have to transform your x-coordinate, which is epoch-millisecond time, to a zero-based index. You can use this cumbersome method:

def place_line(x, y):
    pen=fplt._makepen(fplt.draw_line_color, style='.')
    ax.price_line = pg.InfiniteLine(angle=90, movable=False, pen=pen)
    x, = fplt._pdtime2index(ax, pd.Series([x])) # convert timestamp to x-index
    ax.price_line.setPos((x,0))
    ax.addItem(ax.price_line, ignoreBounds=True)

fplt.set_time_inspector(place_line, ax=ax, when='click')

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ShivaSmith
Comment options

@highfestiva
Comment options

Answer selected by ShivaSmith
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants