-3

enter image description here

All the data points are in blue color. I want the data points with ID- 0000 on the y-axis to be different color.

I want to plot a dataset as below in python:

Timestamp   ID
0.0000      0000
0.000271    0080
0.000495    0000
0.000736    0081
0.000983    0000
0.001239    0165
0.001484    0000
0.001736    018f
0.001984    0000
0.002229    02a0
0.002465    0000
0.002654    02b0
0.002915    0000
0.003143    0316

Please help. Thanks.

11
  • Welcome to Stack Overflow. You can take a look here. Commented Aug 25, 2018 at 18:01
  • have you tried the most obvious df.plot() ... Commented Aug 25, 2018 at 18:04
  • @VasilisG. Hi, I already tried that but no plot is shown in output. Also, there is no error but the output is blank. Commented Aug 25, 2018 at 18:08
  • 1
    Your IDs are some strings, not just numbers. What output plot do you expect? Commented Aug 25, 2018 at 19:15
  • 1
    @Lovleen could you include the code which gives the plot? It is not clear what information the color will encode... What is the wanted color for id different than 0000? Commented Aug 25, 2018 at 21:33

1 Answer 1

0

Here is a solution using Numpy and Matplotlib:

import numpy as np
import matplotlib.pylab as plt

timestamp = np.linspace(0, 1, 7)
ID = np.array(['0000', '0080', '0000', '018f', '0uu00', 'hello', '0000'])
zero_points = (ID == '0000')  # define a selection mask
non_zero_points = np.logical_not(zero_points)

plt.plot(timestamp[non_zero_points],  ID[non_zero_points], 'bo', label='not 0000')
plt.plot(timestamp[zero_points],  ID[zero_points], 'ro', label='0000')
plt.xlabel('time'); plt.ylabel('values'); plt.legend();

which gives:

example graph

The idea is to create a boolean array which is later use to select each group of points. (There is maybe better way to write this, for instance by setting a color value for each point in a scatter plot...)

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.