I am trying to plot my data using plt.subplots. I have three main variables, as follow:
x = DF["Time"] y = DF["recording1"] n = DF ["recording2"]
I am trying to plot y over x, while label y (as a text) with n. The problem is that n has some missing values which I do not want them to appear in the figure.
- So how can I plot the figure while ignoring the nan values?
- How can I draw multiple lines corresponding with each raw based on the value of recording1
fig, ax = plt.subplots(figsize=(15, 8))
ax.scatter(x, y)
plt.title("test")
plt.xlabel("Time")
plt.ylabel("recording1")
texts = []
for i, txt in enumerate(n):
texts.append(ax.annotate(txt, (x[i], y[i]), xytext=(x[i],y[i]-.03),
ha='center',
fontsize=8))
adjust_text(texts)
groups = DF.groupby("recording2")
for name, group in groups:
plt.plot(group.Time, group.recording1,
marker='o', linestyle='', markersize=6, label=name)
source https://stackoverflow.com/questions/76105473/how-can-i-ignore-missing-values-when-plotting-using-subplot
Comments
Post a Comment