Ask Your Question
0

Plot spines show in middle of graph

asked 2023-08-12 15:53:47 +0100

GPN gravatar image

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 flag offensive close merge delete

Comments

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

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

2 Answers

Sort by ยป oldest newest most voted
0

answered 2023-08-13 07:15:23 +0100

achrzesz gravatar image

updated 2023-08-13 11:56:54 +0100

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
edit flag offensive delete link more

Comments

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)
GPN gravatar imageGPN ( 2023-11-21 22:02:24 +0100 )edit
1

answered 2023-11-21 22:13:13 +0100

GPN gravatar image

updated 2023-11-21 22:13:44 +0100

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2023-08-12 15:48:13 +0100

Seen: 89 times

Last updated: Nov 21 '23