2

so this a section of my code, it runs and opens a graph but there is no plot points

fig =plt.figure(1)
data= [1.3,2.4]
for i in range(0,2):
    emittx=data[i];
    turns = 1+i;
    plt.plot(turns,emittx,'-r')
plt.show()

stuck because I cant really understand why

8
  • Can you give an example which is runnable? That is, containing data1? And I assume plt is matplotlib.pyplot? Commented Jan 29, 2014 at 10:48
  • why do you have plot(...) in a loop? I think you should be constructing lists/arrays of your x and y points and calling plot once. Commented Jan 29, 2014 at 10:54
  • 3
    Welcome to SO, sorry you got a rather unfriendly welcome. The problem is that you are plotting a single point using a line style with out markers. Change to plot(turns, emittx, 'or') and you will get markers. Commented Jan 29, 2014 at 14:34
  • 3
    Annoyingly all of the users who voted to close have no or minimal rep in python or matplotlib. There is enough information here for this to be a valid question. It would be better to include some fake-data to plot instead of trying to plot your actual data. Commented Jan 29, 2014 at 14:38
  • 3
    I figured the problem out, I took the plotting routine out of the loop (it wasnt supposed to be in there anyway) and wrote emittx and turns as an array and it plotted fine :) Commented Jan 29, 2014 at 15:16

1 Answer 1

2

As was stated in the comments, the problem is because you are repeatedly (for loop) plotting a SINGLE point and asking matplotlib to use a line ('-') to connect the single point.

Either plot an array of two or more points (e.g. [2.3, 4.4]) or use markers to represent the data ('o'). For example:

fig =plt.figure(1)
data = [1.3,2.4]
for i in range(0,2):
    emittx=data[i];
    turns = 1+i;
    plt.plot(turns,emittx,'or', markersize=10)
plt.show()

should allow you to plot single points.

Sign up to request clarification or add additional context in comments.

Comments

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.