0

I've been browsing everywhere to find answers on how to plot a pandas dataframe using sympy python but the results are still nil, even though here and here are available as learning materials, but I'm still a beginner, it's still difficult to get the output I want.

this is my code

from sympy.plotting import plot
import pandas as pd
from sympy import *
import numpy as np
x = symbols("x")
ekpr = x
data = {
   "name": ["Lionel Messi", "Cristiano Ronaldo "],
   "country": ["Argentina", "Portugal"]
}
df = pd.DataFrame(data,columns=["name","country"])
xvals1 = df.loc[0, "name"]
xvals2 = df.loc[0, "country"]
yvals1 = [ekpr.subs(x, xi) for xi in xvals1]
yvals2 = [ekpr.subs(x, xi) for xi in xvals2]

# add markers to the evaluated coordinates
markers = [{'args': [xvals1, yvals2, 'ro']}]

xvals2 = [(0, xi, xi) for xi in xvals1]
yvals2 = [(yi, yi, 0) for yi in yvals2]
# add these lines to the markers dictionary
for xv, yv in zip(xvals2, yvals2):
    markers.append({'args': [xv, yv, 'r--']})
p = plot(ekpr, xlim=[0, 7], ylim= [0, 7], markers=markers)

my code output image

I want (Lionel Messi, Argentina) connected to the x and y axes. Any help will be greatly appreciated.

Fahrizal
  • 47
  • 6
  • Can you provide an example of what you want the dataframe to look like before you plot it ? It is not exactly clear from your code. – ScottC Oct 15 '22 at 12:13
  • I have edited my question, so what I want is (Lionel Messi, Argentina) to have a relation on the x and y axes with coordinates – Fahrizal Oct 15 '22 at 12:33
  • `sympy.plot` is intended for use with `sympy` expressions. Why are you trying to use it with `pandas`? Doesn't `pandas` have its own plotting tools? – hpaulj Oct 15 '22 at 15:22
  • sorry i'm still a beginner, can you help me with another way to plot to get the output as i want? – Fahrizal Oct 15 '22 at 15:27
  • Use matplotlib directly rather than SymPy's `plot` function. – Oscar Benjamin Oct 18 '22 at 14:56
  • Thanks for your suggestion, but so far I want to use sympy plotting – Fahrizal Oct 18 '22 at 23:43

0 Answers0