0

I'm just trying to graph some simple data and whether I try to do it with plot or subplot it comes out the same. All values in my lists are positive but the y axis is acting like a number line with only positives.

enter image description here

import matplotlib.pyplot as plt


xVal = []
yVal1 = []
yVal2 = []
yVal3 = []
data = []

# load data
with open(r"path", 'r') as f:
data = f.readlines()

yVal1 = data[0].split(",")
yVal2 = data[1].split(",")
yVal3 = data[2].split(",")

del yVal1[-1]
del yVal2[-1]
del yVal3[-1]

print(yVal1)
print(yVal2)
print(yVal3)

# graph dem bois
xVal = [*range(0, len(yVal1))]

'''fig, ax = plt.subplots(3)

ax[0].plot(xVal, yVal1)
ax[0].set_title("pm5")

ax[1].plot(xVal, yVal2)
ax[1].set_title("pm7.5")

ax[2].plot(xVal, yVal3)
ax[2].set_title("pm10")

fig.suptitle("Particulate Levels over time")'''

plt.plot(xVal, yVal3)
plt.show()
2
  • 1
    convert y-vals from strings to floats. Commented Jan 25, 2023 at 1:03
  • @JodyKlymak Thank you! I cannot believe I overlooked that Commented Jan 25, 2023 at 18:15

1 Answer 1

0

As per the comment by Jody Klymak I converted the string lists into float lists and it worked.

fyVal1 = [float(x) for x in yVal1]
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.