Harun
Harun

Reputation: 31

I'm having trouble plotting graphs in Python 3.7. How can I do it?

I have a question. I am using Raspiberry Pi 4 python 3.7.

value = adc.read(channel=0)
array.append(value)

I added the ADC data to the array. The duration of ADC data is always 50 ms.

So this is how I defined the X-axis for duration: (How else can I do for more professionel?):

xpoints=list(np.array([0,50]))

I want to show this in graph.

The X-axis on the chart will be between 0-50. Y axis will be array values.

Trial 1 worked, no problem;

plt.plot(array)
plt.show()

Trial 2 worked, no problem;

plt.plot(xpoints)
plt.show()

But; Trial 3 did not work. There is problem!!! Graph drawing does not appear on the screen. Why is that?;

plt.plot(xpoints,array)
plt.show()

Trial 4 worked fine; Instead of ADC data, I created the y-axis myself;

xpoints=list(np.array([0,50]))
ypoints=list(np.array([0,1000]))
plt.plot(xpoints,ypoints)
plt.show()

Why isn't Trial 3 working? Can you help me?

Upvotes: 2

Views: 57

Answers (1)

Harun
Harun

Reputation: 31

Thanks to the commenters' help, I solved the problem by replacing this:

xpoints = list(np.array([0, 50]))

With this:

xpoints = np.linspace(0, 50, len(array))

Upvotes: 1

Related Questions