Trying to draw an InfiniteLine on mouse-click, but won't display #328
-
Hi, I know I'm processing the mouse click just fine (by using set_time_inspector()), because I can see a print statement execute. Right after the print(), I'm trying to draw a vertical line on top of the candle I clicked on, using example code from complicated.py. So I'm trying this: ax.price_line = pg.InfiniteLine(angle=90, movable=False, pen=fplt._makepen(fplt.draw_line_color))
pen=fplt._makepen(fplt.draw_line_color, style='.'))
ax.price_line.setPos(x)
ax.price_line.pen.setColor(pg.mkColor(fplt.foreground))
ax.addItem(ax.price_line, ignoreBounds=True) But I can't ever see a vertical line be displayed... I also tried calling fplt.refresh() at the end, which made no difference. I've also tried various colors, but to no effect. I'm using the x value that automatically gets passed in via set_time_inspector(). Am I missing something basic with how to get a newly drawn item to display? Thanks 😄 p.s. This application is a bit unusual because I'm using: app = QApplication([])
win = QMainWindow()
add_menus(win)
fplt.display_timezone = None
fplt.refresh()
# fplt.show()
win.show()
app.exec() Note how I need to use win.show()... can't use fplt.show() when using windows this way. p.p.s. My ax is created as: ax, ax2 = fplt.create_plot('S&P 500 MACD', rows=2, maximize=False) This ax gets added, via: layout.addWidget(ax.vb.win) in add_menus() -- def add_menus(win):
main_widget = QWidget()
layout = QGridLayout()
main_widget.setLayout(layout)
layout.addWidget(ax.vb.win)
win.setCentralWidget(main_widget)
win.resize(1000, 800)
win.setWindowTitle('Market Master')
menu_bar = QMenuBar()
file_menu = menu_bar.addMenu('File')
menu_bar.show()
win.setMenuBar(menu_bar) Maybe the way I'm handing my QApplication and QMainWindow means I need to do some other step to get items that are newly added to my ax to display? It seems like it must be something like that... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
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') |
Beta Was this translation helpful? Give feedback.
You have to transform your x-coordinate, which is epoch-millisecond time, to a zero-based index. You can use this cumbersome method: