1
from sympy.abc import *
from sympy import *
plot(*Array([4,6,8]).applyfunc(lambda m:sec(x).series(n=m).removeO()),sec(x),(x,-pi/2,pi/2),ylim=(0,4))

this gives out

enter image description here

I want the y-axes to be from 0-4

I have read the Keyword Arguments, but didn't find any other handle expect ylim.

AsukaMinato
  • 1,017
  • 12
  • 21
  • Note that just plotting `plot(x*x+1, ylim=(0, 4))` also has this empty space between 0 and 1. (And not setting the `ylim` gives an even weirder plot). – JohanC Apr 17 '20 at 14:18

1 Answers1

1

This seems to be the standard way sympy draws plots that don't cross the x-axis. Here is another post with a similar plot.

A possible workarround is to draw an invisible plot near 0,0:

from sympy import plot, pi, sec
from sympy.abc import x

plot1 = plot(*Array([4, 6, 8]).applyfunc(lambda m: sec(x).series(n=m).removeO()), sec(x), 
             (x, -pi / 2, pi / 2), ylim=(0, 4), show=False)
plot2 = plot(0, (x, 0, 1 / 1000), line_color='none', show=False)
plot1.append(plot2[0])
plot1.show()

sample plot

Note that for more complex customization, the plot can be moved to matplotlib.

JohanC
  • 71,591
  • 8
  • 33
  • 66
  • Yes, it is. Sympy's plotting tends to be quick and without much options. There are some even more [tricky ways](https://stackoverflow.com/a/46813804/12046409) to move the plots to matplotlib and do the customization there. – JohanC Apr 17 '20 at 14:57