1

I have created two lines in a Sympy plot and would to add markers to each line. Using the tip from this post, the following does what I expect.

import sympy as sp

x = sp.symbols('x')
sp.plot(x,-x, markers=[{'args' : [5,5, 'r*'], 'ms' : 10},
                      {'args' : [5,-5,'r*'],'ms' : 10}])

However, when I break up the above call into two separate plot commands, each with their own set of markers, both lines show up, but only the marker on the first line shows up.

p0 = sp.plot(x, markers=[{'args' : [5,5, 'r*'],'ms' : 10}],show=False)
p1 = sp.plot(-x,markers=[{'args' : [5,-5,'r*'],'ms' : 10}], show=False)

p0.extend(p1)
p0.show()

What am I missing?

Update: One reason for breaking up the single call into two plot calls is to add custom labels to each expression.

Donna
  • 1,390
  • 1
  • 14
  • 30

1 Answers1

1

Sadly, the extend method only consider the data series, not the markers. You can index the plot object in order to access the data series and apply a label. For example:

from sympy import *
var("x")
p = plot(x,-x, markers=[{'args' : [5, 5, 'r*'], 'ms' : 10, "label": "a"},
                      {'args' : [5, -5, 'r*'],'ms' : 10, "label": "b"}], show=False, legend=True)
p[0].label = "a"
p[1].label = "b"
p.show()

Note that you have to set legend=True to make the legend visible.

Davide_sd
  • 10,578
  • 3
  • 18
  • 30
  • 1
    Thanks, @David_sd. And learned quite a bit about Sympy plotting by reading your Sympy Backend [https://sympy-plot-backends.readthedocs.io/en/latest/overview.html]. (I needed something much simpler here, though, and so restricted myself to just using Sympy). – Donna Nov 26 '22 at 20:39