Closed LSYS closed 3 months ago
I've encountered the same exact issue today, so I've been investigating it a bit to find a temporary workaround, but without success so far.
However, here are some elements if it can help someone else investigating the problem too:
After generating a forestplot (filling the "annote" and "annoteheaders" parameters, and setting the "table" parameter to True), I stored it in a fp
variable. From fp
, I can access the content of the "invisible" column labels through this line of code:
fp.yaxis.get_majorticklabels()[-1]
So the column labels are not really deleted from the plot, they are just invisible for some reason.
I've ruled out things like incorrect font color (e.g. white on white) or incorrect font size (e.g. very small font sizes). I've also been trying to tweak parameters like zorder
or set_visible
, without success.
My hypotheses so far is that either the labels are hidden behind another matplotlib element that takes precedence over them, or they are plotted in a position outside the plot (even though fp.yaxis.get_majorticklabels()[-1].get_position()
doesn't seem to indicate this, when we compare to a plot without this "invisible labels" problem).
Hopefully this might be helpful to fix the issue.
I just found a quick and (very dirty) workaround, not sure if it will work in all scenarios, but here it is:
Once you stored the forest plot if a fp
variable, simply increase the upper limit of the y axis with the following line of code:
offset=0.3
fp.set_ylim((fp.get_ylim()[0], fp.get_ylim()[1]+offset))
plt.show()
You may have to try different values for offset
, depending on the situation.
As for a longer-term fix, it looks like the issue is with the labels being cropped by a too short upper limit on the y axis, when the dataframe has too few rows. I have absolutely no idea where this problem occurs in the codebase, but I'll try to investigate it further if I have some time on my hands one of these days (not sure it will happen though :( ).
@LSYS Ah, I just saw the abandoned status on this bug. If in some hypothetical future I submit a pull request to fix the issue, will you accept it? (I don't want to spend too much time on it for nothing!)
Continuing some testing on my local machine, in https://github.com/LSYS/forestplot/blob/04b8858d62597bd1f1b5d4085dde875c890f7eb9/forestplot/plot.py#L537, setting negative_padding
always to 0.5, that is replacing
if annoteheaders or right_annoteheaders:
negative_padding = 1.0
else:
negative_padding = 0.5
by
negative_padding = 0.5
solves the issue in the example given in https://github.com/LSYS/forestplot/blob/main/docs/assets/issue52-table-does-not-work-6rows-or-fewer.ipynb
So that's surely negative_padding the culprit here. Fixing the issue would require to check possible side-effects of keeping negative_padding
constant.
@jeanbaptisteb give me some time to look at this. But absolutely, if you submit a PR to fix it with tests passing (plus other example figures all looking as expected), it should be accepted.
@jeanbaptisteb i did a quick test and seems to work, do you want to make a PR for this?
@LSYS I'd prefer to make sure that the fix I suggested does not break something else in the process. Hopefully this week I should have some time on my hands to do a bit of extensive testing. I'll let you know that by the end of the week, but if you have no news from me by friday, it's likely that I won't have the time to look into it (in this case, feel free to add yourself my suggested fix).
@jeanbaptisteb got it, thanks!
See issue48-table-does-not-work-6rows-or-fewer.ipynb.