0

I am trying to plot a scatter diagram. It will take multiple arrays as input but plot into a single graph. Here is my code:

import numpy as np
import os
import matplotlib.pyplot as plt

ax = plt.gca()
n_p=np.array([17.2,25.7,6.1,0.9,0.5,0.2])   
n_d=np.array([1,2,3])
a_p=np.array([4.3,1.4,8.1,1.8,7.9,7.0])
a_d=np.array([12,13,14])

ax.scatter = ([n_d[0]/n_d[1]],[n_p[0]/n_p[1]])
ax.scatter = ([a_d[0]/a_d[1]],[a_p[0]/a_p[1]])

I will read the arrays from csv file, here I just put a simple example (for that I imported os). I want to plot the ratio of array element 2/ element 1 of n_p (as x-axis) and same with n_d (as y-axis). This will give a point in the graph. Similar operation will be followed by a_p and a_d array, and the point will be appended to the graph. There will be more data to append, but to understand the process, two is enough. I tried to follow example from here. If I use the color, I get syntax error. If I do not use color, I get a blank plot.

Sorry, my coding experience is beginner so code is rather nasty. Thanks in advance.

3
  • 1
    ax.scatter(...) not ax.scatter = (...) this is a typo. Call out typos in the comments, because question with typos are typically closed and deleted, as they aren't considered beneficial to the community. Commented Aug 10, 2021 at 20:32
  • thanks @TrentonMcKinney I have corrected it. Commented Aug 10, 2021 at 20:49
  • Don't correct the question, because the typo is what was causing the error it seems. Rolled back Commented Aug 10, 2021 at 20:51

1 Answer 1

3

remove the = from the function call!

import numpy as np
import os
import matplotlib.pyplot as plt

ax = plt.gca()
n_p=np.array([17.2,25.7,6.1,0.9,0.5,0.2])   
n_d=np.array([1,2,3])
a_p=np.array([4.3,1.4,8.1,1.8,7.9,7.0])
a_d=np.array([12,13,14])

ax.scatter([n_d[0]/n_d[1]],[n_p[0]/n_p[1]])
ax.scatter([a_d[0]/a_d[1]],[a_p[0]/a_p[1]])
Sign up to request clarification or add additional context in comments.

2 Comments

Could you tell me whats is the ax=plt.gca() mean?
it means return the axis that is currently focused, and if no axis exists then create one ... it's actually better to use something like f, ax = plt.subplots() instead of plt.gca()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.