In the current (1.18) sympy version, the old way to access the matplotlib isn't supported anymore.
Sympy's plotting lists a number of elements you can change or add to a sympy plot. The list is quite long, but unfortunately not documented in detail. Examples are title
, label
, xlabel
, xscale
, xlim
, ... You can also add markers
, rectangles
and annotations
via lists of dictionaries. See e.g. How to customize and add extra elements to Sympy plots
To add a title, you can just write sympy.plot_implicit(..., title='my title')
.
If you need more matplotlib fine-tuning, you can "move the plot to matplotlib", as described in Display two Sympy plots as two Matplotlib subplots.
For your example, the code could look like:
import matplotlib.pyplot as plt
from sympy import plot_implicit, Eq, S
from sympy.abc import x, y
def move_sympyplot_to_axes(p, ax):
backend = p.backend(p)
backend.ax = ax
backend._process_series(backend.parent._series, ax, backend.parent)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_position('zero')
ax.set_xlabel(ax.get_xlabel(), ha='right', x=1, labelpad=0)
ax.set_ylabel(ax.get_ylabel(), ha='right', va='top', y=1, labelpad=0, rotation=0)
plt.close(backend.fig)
formattedQ = Eq (x**(S(2)/3) + y**(S(2)/3), 8)
p = plot_implicit(formattedQ, (x, -25, 25), (y, -25, 25), show=False)
fig, ax = plt.subplots()
move_sympyplot_to_axes(p, ax)
ax.set_title('formattedQ')
ax.set_aspect('equal')
plt.show()
