# Plot spines show in middle of graph

Hi. I am new to SageMath. I like what I see, thanks!

I ran into a tiny but annoying problem: I draw a region_plot and it works very well, but the spines of the plot are drawn down the middle. I tried to make them go away using the standard matplotlib capabilities but they will not disappear. Here is my code:

reset()

a,b,c,x,y = var('a b c x y')

from matplotlib import spines, axes
i = 16
p = region_plot(
tan(x^2 - y^2)>0,
(-i*pi,+i*pi), (-i*pi,+i*pi),
incol='green',outcol='lightblue',
)
p.matplotlib().axes[0].spines[['left', 'bottom']].set_position('zero')
p.matplotlib().axes[0].spines[['top', 'right']].set_visible(False)
p


I am using SageMath on - Ubuntu 22.04 installed in WSL - Notebook is VSCode notebook with vscode-Jupyter extension - Vscode version 1.80

The entire above code is run in a single cell

Thanks

edit retag close merge delete

I don't understand what do you mean by "spines", maybe the axes? You would like to remove axes?

( 2023-08-15 13:01:32 +0100 )edit

Sort by ยป oldest newest most voted

Some way to make them go is:

from matplotlib import rcParams
rcParams['xtick.major.size'] = rcParams['xtick.minor.size'] = 0
rcParams['ytick.major.size'] = rcParams['ytick.minor.size'] = 0
a,b,c,x,y = var('a b c x y')
i = 2
p = region_plot(
tan(x^2 - y^2)>0,
(-i*pi,+i*pi), (-i*pi,+i*pi),linewidths=0,
incol='yellow',outcol='white',plot_points=500,fontsize=16,
ticks=[pi/2,pi/2],tick_formatter=[pi,pi])
p


If you need the ticks outside, you can try:

p.show(frame=True,axes=False)


or

a,b,c,x,y = var('a b c x y')
i = 2
p = contour_plot(
tan(x^2 - y^2),
(-i*pi,+i*pi), (-i*pi,+i*pi),linewidths=0,
contours=[0,0.001],cmap='coolwarm',
plot_points=500,fontsize=16,
ticks=[pi/2,pi/2],tick_formatter=[pi,pi])
p

more

Thank you! The key point was

p.show(frame=True,axes=False)


which put the axes outside the plot. But actually to completely get rid of the spines, the right line is

p.show(frame=False,axes=False)

( 2023-11-21 22:02:24 +0100 )edit

With the advice from @achrzesz and a bit more work, the correct solution is

from sage.all import *
from sage.numerical.optimize import minimize, find_local_maximum
from IPython.display import display, Math, Latex
def showm(v):
display(Math(latex(v)))

x,y = var('x y')

from matplotlib import spines, axes
i = 16
p = region_plot(
tan(x^2 - y^2)>0,
(-i*pi,+i*pi), (-i*pi,+i*pi),linewidths=0,
incol='green',outcol='lightblue',
)
p.show(frame=False,axes=False)


I hope this helps someone.

GPN

more