-
-
Notifications
You must be signed in to change notification settings - Fork 480
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
Further support for matplotlib 3.6 #34693
Comments
comment:1
Currently making sure that this it the only change required and providing support to sage-on-gentoo users already using matplotlib 3.6.x before pushing a branch here. |
Author: François Bissey |
Branch: u/tornaria/matplotlib-3.6 |
comment:2
The attached branch will let you build the doc with matplotlib 3.6. New commits:
|
Commit: |
Changed branch from u/tornaria/matplotlib-3.6 to u/fbissey/MPL3.6_docbuilding |
comment:4
Is this ready for review? |
comment:5
Yes, it is ready.Our consensus at #34668 is that the point of this particular example is unclear. So, removing it does not seem to be a big deal. |
comment:6
I'm hitting the same error ( |
comment:7
Possibly related: #29210 scipy.optimize.newton does not accept Sage input anymore |
comment:8
Yes, I am now wondering if it is an issue that matplotlib (and scipy) may need to adapt to new stuff in numpy. But we cannot leave the plot in, since it breaks building the doc. |
comment:9
Replying to François Bissey:
It is clear. We can use symbolic values as tick marks. It is a useful feature. I may use it (though I never did :)
Removing a feature to upgrade a package is a big deal. I investigated the real cause of the failure. Fortunately I found it. It is a kind of bug in matplotlib 3.6. I reported it to upstream: Let's see how they react before we proceed. |
comment:10
In the upstream discussion matplotlib/matplotlib#24557 (comment), they suggested to make our symbolic objects behave more
or numpy-array-like:
I will investigate the former possibility. We have sage: a = sqrt(2)
sage: a.is_infinity()
False but I don't know how to "add |
comment:11
So Sage integers are numbers from the perspective of numpy. How does it do it? |
comment:12
BTW,
Strange... |
comment:13
I don't know if that's the mechanism why it works, but our |
comment:14
Replying to Matthias Köppe:
I tried that, but doesn't work. Not sure I missed something... |
comment:15
Voilà, I found it. It is https://numpy.org/doc/stable/reference/arrays.interface.html |
comment:16
and https://numpy.org/doc/stable/reference/arrays.dtypes.html Then class Symbolic(object):
__array_interface__ = {'typestr': 'f'}
def __init__(self, a, b):
self.num = a
self.den = b
def __str__(self):
return '{}/{}'.format(self.num, self.den)
def __float__(self):
return float(self.num / self.den)
import matplotlib.pyplot as plt
import numpy as np
import sympy as sym
from matplotlib.ticker import FixedLocator, NullLocator, FuncFormatter
# make data
x = np.linspace(0, 3, 100)
y = 2 * x + 1
# plot
fig, ax = plt.subplots()
ax.plot(x, y, linewidth=2.0)
a = Symbolic(1,2)
ax.xaxis.set_major_locator(FixedLocator([a, 1, 2, 3]))
ax.xaxis.set_minor_locator(NullLocator())
ax.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: str(x)))
plt.show() works. Moreover >>> a = Symbolic(2,3)
>>> np.isfinite(a)
True
>>> np.array(a)
array(0.6666667, dtype=float32) Hence so we now know how to make To implement this mechanism for |
comment:17
Does |
comment:18
It can be But I realized a major problem. By the mechanism, |
comment:19
Replying to Kwankyu Lee:
The rescue is to use matplotlib's Anyway, implementing this together with I don't know how frequently the symbolic tick mark feature is used by sage users. If no one uses it :) then perhaps we may turn off this feature while we upgrade matplotlib to 3.6. |
comment:20
OK. So, it is currently broken and will take some time and efforts to put it right, if there is a will. In the meantime, the branch removes just a plot showcasing the capability because it breaks building the documentation in sage-on-distros which already have matplotlib 3.6.x available. |
comment:21
How about just commenting them out mentioning this ticket? But no one uses it? I really don't know. How about posting on sage-devel to prevent some one later to complain that his/her code doesn't work anymore... |
comment:22
I definitely use this feature (comment:6); -1 on removing the test |
comment:23
Replying to Matthias Köppe:
+1. Meanwhile I learned enough matplotlib to make up a simple fix for this ticket. |
Changed author from François Bissey to Kwankyu Lee |
Changed branch from u/fbissey/MPL3.6_docbuilding to u/klee/MPL3.6_docbuilding |
New commits:
|
This comment has been minimized.
This comment has been minimized.
Branch pushed to git repo; I updated commit sha1. New commits:
|
Reviewer: Matthias Koeppe |
comment:28
I can confirm that this also fixes the issue in my plotting code. Thanks a lot for working on it! |
comment:29
Thanks. I also checked the branch with #34796 that upgrades matplotlib to 3.6. It works well. |
Changed branch from u/klee/MPL3.6_docbuilding to |
#34668 was focusing on making doctests pass but did not test docbuilding.
The following plot in
src/sage/plot/plot.py
is causing the building of the documentation to fail horribly.
Tests of this plot were disabled in #34668 and now we need to remove the plot. The whole example needs to be replaced by something that works.
We could not overcome the problem of symbolic values that numpy rejects, but instead made a fix to circumvent numpy and revived the doctest and the example.
CC: @tornaria
Component: documentation
Author: Kwankyu Lee
Branch/Commit:
6458968
Reviewer: Matthias Koeppe
Issue created by migration from https://trac.sagemath.org/ticket/34693
The text was updated successfully, but these errors were encountered: