FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: Datetime axis with usetex is unclear · Issue #21518 · matplotlib/matplotlib · GitHub

Repository navigation

[Bug]: Datetime axis with usetex is unclear #21518

Closed

Description

Bug summary

The spacing for a datetime axis when using usetex=True is unclear in matplotlib version 3.4 when comparing it to 3.3.

Code for reproduction

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

np.random.seed(1)
matplotlib.rcParams["text.usetex"] = True

dates = pd.date_range("2020-01-01 00:00:00", end="2020-01-01 00:10:00", periods=100)
data = np.random.rand(100)

fig, ax = plt.subplots(constrained_layout=True)
ax.plot(dates, data)
plt.savefig(matplotlib.__version__ + ".png")

Actual outcome

Example of how it look in 3.3.4:

Example of how it look in 3.4.3:

Expected outcome

The ideal case would be to have the spacing from version 3.3 in a tex format.

Operating system

Windows

Matplotlib Version

3.4.3

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Other libraries

No response

Installation

conda

Conda channel

conda-forge

Activity

  1. QuLogic commented on Nov 2, 2021

    Member

    Can you reproduce this without Pandas?

  2. hoxbro commented on Nov 2, 2021

    ContributorAuthor

    Yes. Done with the following code:

    from datetime import datetime, timedelta
    
    import matplotlib
    import matplotlib.pyplot as plt
    import numpy as np
    
    np.random.seed(1)
    matplotlib.rcParams["text.usetex"] = True
    
    dates = np.arange(datetime(2020, 1, 1), datetime(2020, 1, 1, 0, 10), timedelta(seconds=6))
    data = np.random.rand(100)
    
    fig, ax = plt.subplots(constrained_layout=True)
    ax.plot(dates, data)
    plt.savefig(matplotlib.__version__ + ".png")
  3. timhoffm commented on Nov 2, 2021

    Member

    From the image it looks like 3.3.4 did not render the dates using TeX. 3.4.3 does render with TeX but gets the spacing wrong.

  4. jklymak commented on Nov 2, 2021

    Member

    Support for this came in #18558 but I guess protecting spaces didn't happen properly.

  5. anntzer commented on Nov 2, 2021

    Contributor

    I guess that's related to #18520 (comment).
    Edit: I think I have a reasonable implementation of \text that can go on top of my current mathtext-related PRs, plus a couple of others...

  6. hoxbro commented on Nov 3, 2021

    ContributorAuthor

    I get the plot I want by monkey patching _wrap_in_tex:

    def _wrap_in_tex(text):
        text = text.replace('-', '{-}').replace(":", r"{:}").replace(" ", r"\;")
        return '$\\mathdefault{' + text + '}$'
    
    matplotlib.dates._wrap_in_tex = _wrap_in_tex

  7. jklymak commented on Nov 8, 2021

    Member

    @anntzer @hoxbro can either of you put in a PR for this?

  8. anntzer commented on Nov 8, 2021

    Contributor

    (I don't have a quick fix, it'd go on top of my mathtext prs plus some more...)

  9. hoxbro commented on Nov 8, 2021

    ContributorAuthor

    @anntzer Should I add a PR with my quick fix which you can then remove/update in a following PR?

  10. anntzer commented on Nov 8, 2021

    Contributor

    Go for it.

  11. added this to the v3.5.0 milestone on Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL