Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

My dataset is as follows:

G R Y
1 1 0
1 2 1
1 3 2
1 4 4
1 5 2
2 1 1
2 2 2
2 3 3
2 4 2
3 1 0
3 2 1
3 3 2
3 4 2
3 5 3

I want to know how to write the correct matplotlib code to plot the points as follows:

enter image description here

share|improve this question
2  
Can you show us what you tried so far? –  plonser 18 hours ago
    
is this your data a csv/tsv? –  James Kelleher 18 hours ago

1 Answer 1

You could just split up your data according to the three sections you have, graph each group separately, and then attach the graphs together:

fig, axes = plt.subplots(1, 3, sharey=True)
Y = [0, 1, 2, 4, 2, 1, 2, 3, 2, 0, 1, 2, 2, 3]
Y0 = Y[0:6]
Y1 = Y[5:10]
Y2 = Y[9:15]
axes[0].plot(Y0)
axes[1].plot(Y1)
axes[2].plot(Y2)
plt.ylim([0, 5])
subplots_adjust(wspace=0)

That will get you pretty close to what you need (though I admit some of the the x-axes could use a little extra formatting):

enter image description here

If I were you I would enter that line by line, hitting plt.draw() after every line of matplotlib code to see what exactly is going on.

share|improve this answer
    
Thanks, it is close to the figure that I want. –  Lijie Xu 17 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.