0

I don't feel like the question explained my point clearly, but I'll try my best here. I have 3 arrays in the form:

import numpy as np
x = np.array([1,2,3,4,5,6])
y = np.array([7,8,9,10,11,12])
label = np.array(['a','b','c','d','e','f'])

I'd like to be able to manipulate them such that I can end up with a plot with 6 different points of varying formats. For example, the first point would be at x=1, y=7, and it should correspond to 'a' in the legend. I could do something like:

import matplotlib.pyplot as pl
pl.plot(x[0], y[0],'r+')
pl.plot(x[1], y[1],'g+')

going all the way to the 5th element, but there should be a more concise way of doing it. I think you need a for loop, but I don't really understand how they work and they always return some sort of error. Something like:

for i in len(x):
    pl.plot(x[i],y[i])

Not to mention, I don't really know how I'd go about changing the format individually for whatever the correct version of the above is.

Any ideas? If you can't tell (somehow) I'm pretty Python illiterate so this is pretty confusing for me.

Paul Angus
  • 19
  • 1
  • 4
  • It is better to use plt.scatter(x, y, c=['red', 'blue', 'green', 'yellow', 'cyan', 'black']). You don't have to iterate through. – Hun Apr 11 '16 at 03:53
  • You need `range` if you use the for loop `for i in range(len(x)):`. – John La Rooy Apr 11 '16 at 03:54

0 Answers0