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

Legend does not resize to text content #528

Open
ymk00 opened this issue Jul 24, 2024 · 1 comment
Open

Legend does not resize to text content #528

ymk00 opened this issue Jul 24, 2024 · 1 comment

Comments

@ymk00
Copy link

ymk00 commented Jul 24, 2024

I have a dynamic legend and am trying to have it resize to fit the text content. However, right now the legend will expand but not contract.

Here is a basic example:

import finplot as fplt
import yfinance
import numpy as np

df = yfinance.download("ASTS", interval="1d")
df["Date"] = df.index.astype(np.int64)

ax = fplt.create_plot("ASTS")
legend = fplt.add_legend("", ax=ax)

df[["Open", "Close", "High", "Low"]].plot(ax=ax, kind="candle")

def update_legend_text(x, y):
    row = df.loc[df["Date"] == x].iloc[0]
    legend.setText(f'<span style="color: white;">O: {row["Open"]:.2f} C: {row["Close"]:.2f} H: {row["High"]:.2f} L: {row["Low"]:.2f}</span>')

fplt.set_mouse_callback(update_legend_text, ax=ax, when="hover")
fplt.show()

You can see how the legend will grow larger to accommodate longer text but will not shrink back when going to shorter text.

@highfestiva
Copy link
Owner

Unfortunately I don't know, you'll have to look into the pyqtgraph code for how legends are made to find a solution. GL!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants