1

I have a csv file with the following data.

Time,Type,RX,TX
2013-05-16 18:43:48,UP,0.72,10.86
2013-05-16 18:43:51,DOWN,68.74,1.67
2013-05-16 18:44:06,DOWN,104.01,2.52
2013-05-16 18:43:48,UP,1.21,10.94
2013-05-16 18:44:25,DOWN,104.07,2.54

I want two separate graphs:

  • RX and TX graphed against time for Type=UP
  • RX and TX graphed against time for Type=DOWN

Here is my attempt. My problem is that both graphs contain all data.

plot = matplotlib.mlab.csv2rec(data_file)
fig = matplotlib.pyplot.figure()
subplot1 = matplotlib.pyplot.subplot(1,2,1)
subplot2 = matplotlib.pyplot.subplot(1,2,2)
subplot1.plot(plot.time, plot.rx)
subplot1.plot(plot.time, plot.tx)
subplot2.plot(plot.time, plot.rx)
subplot2.plot(plot.time, plot.tx)

Any ideas how I can do this?

1
  • using plot as a variable name is greatly confusing. I don't quite understand your problem, you are telling it to plot all the data in both graphs, and it is doing so. What have you tried to filter your data? Commented May 17, 2013 at 14:25

1 Answer 1

3

You can first filter your (poorly named) plot array into two separate arrays:

UP_data = plot[plot.type == 'UP']
DOWN_data = plot[plot.type == 'DOWN']

Then plot each separately:

subplot1.plot(UP_data.time, UP_data.rx)
subplot1.plot(UP_data.time, UP_data.tx)
subplot2.plot(DOWN_data.time, DOWN_data.rx)
subplot2.plot(DOWN_data.time, DOWN_data.tx)
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.