Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bug: log scale inserts invalid LaTex code #15

Open
cgahr opened this issue Nov 6, 2024 · 3 comments
Open

Bug: log scale inserts invalid LaTex code #15

cgahr opened this issue Nov 6, 2024 · 3 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@cgahr
Copy link

cgahr commented Nov 6, 2024

If I use a logarithmic scale, the labels use latex code for the ticks. Obviously, this does not work.

To reproduce:

import matplotlib.pyplot as plt
import mpl_typst.as_default  # noqa: F401

fig, ax = plt.subplots(1, 1)
ax.plot([1, 10, 100, 10])
ax.set_yscale("log")
fig.savefig("test.typ")
@cgahr cgahr changed the title Bug: labels on log-axis are not plotted correctly Bug: log scale inserts invalid LaTex code Nov 6, 2024
@rossmeier
Copy link

Upon some further investigating, it looks like matplotlib hardcodes this here: https://github.com/matplotlib/matplotlib/blob/306c8dedaf0dae9d4636438bf7395457ff7bb2c0/lib/matplotlib/ticker.py#L1124
I'm sure there are many other similar problems, but I guess as this is a quite common case that is hardcoded in matplotlib, maybe hardcoding this with a regex would be justifiable.

@cgahr
Copy link
Author

cgahr commented Jan 23, 2025

On my local branch, I solved this by defining #let mathdefault(it) = it in prologue.typ and replacing the curly brackets in a postprocessing step

@daskol daskol self-assigned this Jan 24, 2025
@daskol daskol added the bug Something isn't working label Jan 24, 2025
@daskol
Copy link
Owner

daskol commented Jan 24, 2025

Yes, there are some issues with rendering markup languages other than LaTeX which is the first-class (and the only) citizen in Matplotlib. In early version of mpl-typst, I implemented LogFormatterSciNotation axis formatter (see 08b204c) and then used it as follows.

fig, ax = plt.subplots(...)
ax.yaxis.set_major_formatter(LogFormatterSciNotation())

So base solution is to (re)implement common formatters and then set up axis/tickers/etc manually. Main disadvantage here is manual axis configuration. Also, it takes some time to provide full set of formatters to achieve parity with LaTeX.

In parallel, I will consult with Matplotlib dev board on this topic. Locking to LaTeX undermines universality and extensibility of Matplotlib. It is a strong argument from my perspective.

solved this by defining #let mathdefault(it) = it

This is pretty smart workaround though!

@daskol daskol added the enhancement New feature or request label Jan 24, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants