FIX: Add mtext into RendererBase._draw_as_path() arguments - #31910
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
Thanks! Can you please add a test to ensure this works as expected? |
|
Ah yes, sorry! I have included a test below for this: >>> import matplotlib as mpl
>>> import matplotlib.pyplot as plt
>>> mpl.rcParams['text.usetex'] = True
>>> plt.rcParams['text.latex.preamble'] = r"\usepackage{lmodern}"
>>> x = list(range(5))
>>> plt.plot(x,x)
>>> plt.savefig('test.png', backend='cairo')Based on the information above, it seems that the error occurs only when the Thank you! |
Any idea why? And can you add a test to matplotlib/lib/matplotlib/tests/test_text.py Lines 1310 to 1319 in ca8df27 |
|
I think the error occurs mainly because the matplotlib/lib/matplotlib/backend_bases.py Lines 488 to 509 in ca8df27 More specifically, with matplotlib/lib/matplotlib/backends/backend_cairo.py Lines 463 to 469 in ca8df27 This then calls the matplotlib/lib/matplotlib/text.py Lines 841 to 915 in ca8df27 The I followed the traceback messages a little bit and tried to identity the root cause. I checked two other backend files matplotlib/lib/matplotlib/backends/backend_agg.py Lines 431 to 441 in ca8df27 and backend_pdf.py for comparison.matplotlib/lib/matplotlib/backends/backend_pdf.py Lines 2724 to 2752 in ca8df27 There, they both have similar calls with This is where I noticed that I suspect every backend that has This is my first ever pull request to such a massive repo, so I am still figuring out how and where to write the tests for this according to the docs. Thank you for your patience and understanding! 😄 |
# PR Summary --- Missing 1 positional argument 'mtext' in `RendererBase._draw_text_as_path()` (line 509 of `backend_bases.py`). Small fix by including `mtext=mtext` into `RendererBase._draw_text_as_path()`. This error happens when the user is trying to use LaTeX in matplotlib with matplotlib==3.11.0. # AI Disclosure --- All errors and fixes were done manually.
|
Thanks for your work on this. Writing a test here might be a bit difficult for a newcomer, since it's not in the standard rendering path. I've gone ahead and written one here, as well as rebased, so that we can get 3.11.1 out soonish. |
…910-on-v3.11.x Backport PR #31910 on branch v3.11.x (FIX: Add mtext into RendererBase._draw_as_path() arguments)
PR summary
Why is this change necessary?
User might be unable to use LaTeX formatting for plots.
What problem does it solve?
Fixes the
TypeErrorwith missing positional argument forRendererBase._draw_text_as_path()by addingmtext=mtextinto the arguments.What is the reasoning for this implementation?
The function that calls
RendererBase._draw_text_as_path()already includesmtext=Noneas a default argument. Therefore, thismtextis just passed intoRendererBase._draw_text_as_path()too.AI Disclosure
All fixes and code were done manually.
PR checklist