Davide-sd / sympy-plot-backends

An improved plotting module for SymPy
BSD 3-Clause "New" or "Revised" License
42 stars 9 forks source link

Option to highlight the horizontal & vertical 0 lines in graphs #22

Closed James-G-Hill closed 1 year ago

James-G-Hill commented 1 year ago

I'm not sure if this is required, or whether there is an option that's either documented but I couldn't find it, or undocumented.

When I view charts, particularly for example plot_complex_list charts, it's not obvious to me which lines are the basis for the x & y axis (the line at 0 for each axis). I have to constantly refer back to the labels at the chart edges to determine where points are even just in general relation to the point 0-0.

It would be great to have a simple option to turn on a highlight in some way so that both or either of those lines are more prominent in some way (for example, bold, or a different color to the other lines, or dashed, maybe these could be options).

Maybe there's already a fairly simple way to do this though?

Davide-sd commented 1 year ago

Hello James,

if you are using MatplotlibBackend, you can set the coordinates of the intersection points of the spines with the axis_center keyword arguments, for example:

from sympy import *
from spb import *
var("z")

expr1 = z * exp(2 * pi * I * z)
expr2 = 2 * expr1
n = 15
l1 = [expr1.subs(z, t / n) for t in range(n)]
l2 = [expr2.subs(z, t / n) for t in range(n)]
plot_complex_list((l1, "f1"), (l2, "f2"), axis_center=(0, 0))

image

This however, removes the rectangular spines that "bounds" the plot...

You can find more information about the available keyword arguments by reading the documentation with help(MB).

Alternatively, you'd have to create one horizontal and one vertical line, then combine the plots:

expr1 = z * exp(2 * pi * I * z)
expr2 = 2 * expr1
n = 15
l1 = [expr1.subs(z, t / n) for t in range(n)]
l2 = [expr2.subs(z, t / n) for t in range(n)]

c = 50 # some sufficiently large number
x_axis = plot_list([-c, c], [0, 0], {"color": "k"}, show=False)
y_axis = plot_list([0, 0], [-c, c], {"color": "k"}, show=False)

p1 = plot_complex_list((l1, "f1"), (l2, "f2"), show=False,
        aspect="equal", xlim=(-5, 5), ylim=(-3, 3) # zoom into the interested region
)
(p1 + x_axis + y_axis).show()

image

James-G-Hill commented 1 year ago

Great, thanks for the advice!