Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Python Plotting problem
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Python Plotting problem

by BillPretty on Sat Mar 13, 2021 7:02 pm

I am having problems with the following python script.
I see four graphs, but no data is plotted.

Code:

Code: Select all | TOGGLE FULL SIZE
from gpiozero import CPUTemperature
from time import sleep, strftime, time
import matplotlib.pyplot as plt
import os
import busio
import digitalio
import board
import adafruit_mcp3xxx.mcp3008 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn

# create the spi bus
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

# create the cs (chip select)
cs = digitalio.DigitalInOut(board.D22)

# create the mcp object
mcp = MCP.MCP3008(spi, cs)

# create cpu object
cpu = CPUTemperature()

# Initialise the subplot function using number of rows and columns
figure, axis = plt.subplots(2, 2)

# create an analog input channel on pin 0
chan0 = AnalogIn(mcp, MCP.P0)

while True:
    x= time()   
   
    # plot temperature
    temp = cpu.temperature
    axis[0,0].plot(x,temp)
    plt.draw()
    print ('Core Temperature:' + str(temp))
    plt.pause(1)

    # plot +5V
    adc=chan0.voltage
    axis[0,1].plot(x,chan0.voltage)
    plt.draw()
    print('ADC Voltage: ' + str(chan0.voltage) + 'V')
    plt.pause(1)

BillPretty
 
Posts: 9
Joined: Sun Mar 07, 2021 2:44 pm

Re: Python Plotting problem

by adafruit_support_carter on Mon Mar 15, 2021 5:56 pm

Please don't cross post:
viewtopic.php?f=48&t=176762

adafruit_support_carter
 
Posts: 20146
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.