Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Axes3D set_xbound() doesn't work on negative lower limit with rc_context(), "text.usetex": True when %matplotlib notebook is enabled #18110

New issue

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

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

Already on GitHub? Sign in to your account

Closed
chudur-budur opened this issue Jul 29, 2020 · 5 comments

Comments

@chudur-budur
Copy link

chudur-budur commented Jul 29, 2020

Bug report

Axes3D's set_xbound() (or set_ybound(), set_zbound()) doesn't work on negative lower limit while using with rc_context() and "text.usetex": True. It does not work when %matplotlib notebook is enabled, but it works on %matplotlib inline

However if the bounds are set in positives, it works, otherwise it won't.

Code for reproduction

%matplotlib notebook

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

A = np.random.random((1000,3))
with plt.rc_context({"text.usetex": True, "font.size": 12}):
    fig = plt.figure()
    ax = Axes3D(fig)
    ax.scatter(A[:,0], A[:,1], A[:,2])
    ax.set_xbound([-1,1])
    ax.set_ybound([-1,1])
    ax.set_zbound([-1,1])
    plt.show()

Outcome
A fail case

Another case

%matplotlib notebook

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

A = np.random.random((1000,3))
with plt.rc_context({"text.usetex": True, "font.size": 12}):
    fig = plt.figure()
    ax = Axes3D(fig)
    ax.scatter(A[:,0], A[:,1], A[:,2])
    ax.set_xbound([0,5])
    ax.set_ybound([0,5])
    ax.set_zbound([0,5])
    plt.show()

Outcome
The bounds work, however if you look at the axes tick-labels, you can see that only 0s are in tex, others are not.
Another fail case

Expected outcome
The bounds should work when the lower-bounds are negative, also all the axes tick-labels in the second case should all be in tex.

Matplotlib version

  • Operating system: posix Darwin 19.6.0
  • Matplotlib version: 3.1.3
  • Matplotlib backend (print(matplotlib.get_backend())): nbAgg
  • Python version: 3.7.5 (default, Nov 1 2019, 02:16:23) [Clang 11.0.0 (clang-1100.0.33.8)]
  • Jupyter version (if applicable):
    • jupyter core : 4.6.3
    • jupyter-notebook : 6.0.3
    • qtconsole : 4.6.0
    • ipython : 7.12.0
    • ipykernel : 5.1.4
    • jupyter client : 6.0.0
    • jupyter lab : not installed
    • nbconvert : 5.6.1
    • ipywidgets : 7.5.1
    • nbformat : 5.0.4
    • traitlets : 4.3.3
  • Other libraries:
@chudur-budur chudur-budur changed the title Axes3D's set_xbound() doesn't work on negative lower limit with rc_context(), "text.usetex": True when %matplotlib notebook is enabled Axes3D's set_xbound() doesn't work on negative lower limit with rc_context(), "text.usetex": True when %matplotlib notebook is enabled Jul 29, 2020
@chudur-budur chudur-budur changed the title Axes3D's set_xbound() doesn't work on negative lower limit with rc_context(), "text.usetex": True when %matplotlib notebook is enabled Axes3D set_xbound() doesn't work on negative lower limit with rc_context(), "text.usetex": True when %matplotlib notebook is enabled Jul 29, 2020
@WeatherGod
Copy link
Member

I wonder if this bug and #18112 are actually the result of the same bug?

@timhoffm
Copy link
Member

I wonder if this bug and #18112 are actually the result of the same bug?

Check by setting

ax._autoscaleXon = False
ax._autoscaleYon = False
ax._autoscaleZon = False

if that fixes the issue, it's most likely the same cause.

@chudur-budur
Copy link
Author

chudur-budur commented Jul 30, 2020

I wonder if this bug and #18112 are actually the result of the same bug?

Check by setting

ax._autoscaleXon = False
ax._autoscaleYon = False
ax._autoscaleZon = False

if that fixes the issue, it's most likely the same cause.

No, it does not fix the issue in this post, not sure about #18112 though.

@QuLogic
Copy link
Member

QuLogic commented Jul 30, 2020

In the console for the first one, we see:

RuntimeError: latex was not able to process the following string:
b'$\\u22121.00$'

Here is the full report generated by latex:
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode

(~/.cache/matplotlib/tex.cache/ebebfc358d4c45dc8bf78a97d857a8f8.tex
LaTeX2e <2018-12-01>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/type1cm/type1cm.sty)
(/usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/ts1enc.def
(/usr/share/texlive/texmf-dist/tex/latex/base/ts1enc.dfu)))
(/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifvtex.sty)
(/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty)

Package geometry Warning: Over-specification in `h'-direction.
    `width' (5058.9pt) is ignored.


Package geometry Warning: Over-specification in `v'-direction.
    `height' (5058.9pt) is ignored.

)
No file ebebfc358d4c45dc8bf78a97d857a8f8.aux.
(/usr/share/texlive/texmf-dist/tex/latex/base/ts1cmr.fd)
*geometry* driver: auto-detecting
*geometry* detected driver: dvips

! Package inputenc Error: Unicode character − (U+2212)
(inputenc)                not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.14 ...tsize{12.000000}{15.000000}{\sffamily $−
                                                  1.00$}
No pages of output.
Transcript written on ebebfc358d4c45dc8bf78a97d857a8f8.log.

I do not understand why this only triggers in the notebook, though.

@QuLogic
Copy link
Member

QuLogic commented Jul 30, 2020

Ah wait, that was because my notebook wasn't from the environment and using older Matplotlib.

Current versions have \DeclareUnicodeCharacter{2212}{\ensuremath{-}} in the preamble and should work, except that set_xbound is broken due to #18112 (you can use set_xlim, et al, instead.) The second example also works correctly.

Please update to 3.3.0, but I believe this is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants