iplot: labels for x-axis #892
Replies: 8 comments 2 replies
-
Hi @mortizm1988 , in principle you should simply be able to pass a dictionary with the names of the coefficients as keys and values the new names. But that doesn't seem to be working for me using pf v0.29: import pyfixest as pf
from pyfixest.report.utils import rename_categoricals, rename_event_study_coefs
import numpy as np
df = pf.get_data()
fit1 = pf.feols("Y ~ i(f1, X1)", data = df)
fit2 = pf.feols("Y ~ i(f1, X1) + X2", data = df)
pf.iplot(
models = [fit1],
labels = {
np.str_('C(f1)[0.0]:X1'): "new name",
"C(f1)[0.0]:X1": 'new name 2',
},
) So I would say this is a bug? I can take a closer look at it tomorrow evening. If this also does not work for you, you can also rename the y or x axis ticks manually, as iplot returns a matplotlib figure: fig = pf.iplot(
models = [fit1, fit2, fit3],
labels = rename_categoricals(fit1._coefnames)
)
type(fig)
# matplotlib.figure.Figure
ax = fig.axes[0]
ax.set_yticklabels(['Label A', 'Label B', 'Label C'])
fig |
Beta Was this translation helpful? Give feedback.
-
Hi @mortizm1988 , this is clearly a bug and I opened an issue here #894 If you need to fix this really, really urgently, the code snippet with the error should be this and it is getting called by iplot via _coefplot via coefplot_matplotlib here. I'll try to fix this in the next days but can't make promises (I only work on pf in the evenings and have plans half he evening tomorrow). |
Beta Was this translation helpful? Give feedback.
-
Actually, I figured out the solution! You only rename the "categorical" part of the interaction, not the "full" interaction. Here is an example what I mean by this: import pyfixest as pf
from pyfixest.report.utils import rename_categoricals, rename_event_study_coefs
import numpy as np
df = pf.get_data()
fit1 = pf.feols("Y ~ i(f1, X1)", data = df)
fit2 = pf.feols("Y ~ i(f1, X1) + X2", data = df)
pf.iplot(
[fit1, fit2],
labels = {"C(f1)[0.0]":"var 1"},
) produces So use Note sure if this is really too straightforward? At the very least, we should update the docs. Would you have expected such behavior @mortizm1988? |
Beta Was this translation helpful? Give feedback.
-
Hi @s3alfisc fit3 = pf.feols("Y ~ i(f1, X1,ref=0.0)", data = df)
fit4 = pf.feols("Y ~ i(f1, X1,ref=0.0) + X2", data = df)
pf.iplot(
[fit3, fit4],
coord_flip=False,
labels = {"C(f1)[1.0]":"var 1"},
) Generates the same label for the first coefficient: Btw, I would be happy to help updating/extending the docs. I' don't have that much experience doing PRs but I'm using pf a lot, so please let me know if I could be of some help. |
Beta Was this translation helpful? Give feedback.
-
Yes, you really need to use the "full" name of the variable, which in this case then becomes %load_ext autoreload
%autoreload 2
import pyfixest as pf
from pyfixest.report.utils import rename_categoricals, rename_event_study_coefs
import numpy as np
df = pf.get_data()
fit1 = pf.feols("Y ~ i(f1, X1, ref = 0.0)", data = df)
fit2 = pf.feols("Y ~ i(f1, X1, ref = 0.0) + X2", data = df)
pf.etable(
[fit1, fit2],
labels = {"C(f1, contr.treatment(base=0.0))[1.0]":"var 1"},
type = "md"
) which would give
Not sure if this the most straightforward solution - I guess one could argue that one upside is that it's easy to define a "rule", which would be "provide the full name of variable - everything you would get via |
Beta Was this translation helpful? Give feedback.
-
And awesome to hear that you're using pyfixest a lot! 🌞 If you want to take a stab at clarifying the docs, you could update the description of the and maybe add examples how to effectively use the labels arg for all three functions? I think the easiest way to set up PRs would be to just use the github web UI - first clone the repo and then click on "edit this file" and go through the entire process of opening a PR. There's really nothing that could go wrong - I have to review and approve any changes you make =) |
Beta Was this translation helpful? Give feedback.
-
I sent a PR with the update to the documentation. |
Beta Was this translation helpful? Give feedback.
-
Awesome! I just merged it =) For the examples: I would maybe add examples to the code examples of the docstrings of the individual functions, e.g. here for etable. And then maybe you could also update the how to create nice regression tables section with the examples you've added for |
Beta Was this translation helpful? Give feedback.
-
Hi everyone.
I hope someone can help me further understand how to personalize an iplot.
I'm currently regressing the % of foreign employees across time (fiscal year: "fyear"), for family and nonfamily firms ( "family_control").
My code is as follows:
Beta Was this translation helpful? Give feedback.
All reactions