My issue is closely related to the one here.
I need to access the ticklabels before writing my plot to a file, but when being non interactive there appears to be no way of forcing the generation of ticklabels, or is there? Both fig.canvas.draw() and matplotlib.pyplot.draw() have no effect.
Of course I could generate my own ticklabels, using ax.set_xticklabels(ax.get_xticks()) but I very much like the default formatting of ticks so I would like to rely on matplotlib here.
In the code below method 0 is what I would label the clean solution whereas all other implementations are workarounds, necessary to compensate for the difference of the behaviors of interactive vs non interactive backends. I find the dependence on the interactiveness of the backend problematic. This is because what I often do is to develop a plotting code using an interactive backend and when it's ready I apply it to big data on a HPC were I'm not always provided interactive backends.
agg, works fine, I guess I will just use aggs then.
I'm writing a function that will take a figure, replace all pairs of $ ... $ by \$ ... \$ to turn off mathtex rendering, and then save it to an svg file. I then, using inkscape, convert this svg file into a pdf+pdf_tex file pair for inclusion in latex documents.
I'm not a big fan of pgf but I adore inkscape's way of splitting all graphics from latex by writing the graphics to the pdf document and the latex to the pdf_tex document.
This is indeed pretty much a workaround the issue that one cannot turn off mathtex rendering in matplotlib, but while I'm at it, it also allows me to have ticklabels formatted as $\ticklabel{0.1}$, $\ticklabel{0.2}$ ... so that I can easily modify the appearance of ticks in my latex document later on.
changed the title [-]Force generation of ticklabels when non interactive[/-][+]canvas.draw() does not render tick labels with pdf backend[/+]on Feb 25, 2019
How are you saving the file? Is there any reason to use the pdf backend except for saving? Not saying this isn't a bug, but its a bit funny to use pdf as a non-printing backend; i.e. matplotlib.use('egg') with fig.sqvefig('boo.pdf') works?
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
I'll close this as the vector backends are not particularly meant to be used "live" like this and really should only be used for saving finished figures.
Activity
tacaswell commented on Feb 25, 2019
if you change ot matplotlib.use('agg') does it work?
Why do you need access to the tick labels?
baloe commented on Feb 25, 2019
agg, works fine, I guess I will just use aggs then.
I'm writing a function that will take a figure, replace all pairs of $ ... $ by \$ ... \$ to turn off mathtex rendering, and then save it to an svg file. I then, using inkscape, convert this svg file into a pdf+pdf_tex file pair for inclusion in latex documents.
I'm not a big fan of pgf but I adore inkscape's way of splitting all graphics from latex by writing the graphics to the pdf document and the latex to the pdf_tex document.
This is indeed pretty much a workaround the issue that one cannot turn off mathtex rendering in matplotlib, but while I'm at it, it also allows me to have ticklabels formatted as $\ticklabel{0.1}$, $\ticklabel{0.2}$ ... so that I can easily modify the appearance of ticks in my latex document later on.
tacaswell commented on Feb 25, 2019
You may be interested in the discussion around #12856
I think you have identified an app specific behavior we (at least I) have been thinking of as 'standard' behavior.
jklymak commented on Mar 3, 2019
How are you saving the file? Is there any reason to use the pdf backend except for saving? Not saying this isn't a bug, but its a bit funny to use pdf as a non-printing backend; i.e. matplotlib.use('egg') with fig.sqvefig('boo.pdf') works?
github-actions commented on Jun 1, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
jklymak commented on Jun 1, 2023
I'll close this as the vector backends are not particularly meant to be used "live" like this and really should only be used for saving finished figures.
tacaswell commented on Jun 1, 2023
The core of the problem as that we are lazy about generating tick labels, but the user wants to access them to change the strings.
I think what the OP wants here is the fig.draw_without_rendering() method, but
this was actually fixed by #18408 in mpl 3.4