Python matplotlib MAXTICKS
你好 我在一个包含7个变量和42个数据元素的数据集上得到一个错误“Overses Locator.MAXTICKS”。我让代码在一个不遵循面向对象设计的程序中工作。我正在将应用程序转换为基于GUI的应用程序。我创建了一个类并移动了代码,从那以后,它一直抛出“RuntimeError:Locator试图从729937.416667到733955.541667:Overses Locator.MAXTICKS生成32146个刻度”我在我的Raspberry Pi和我的Ubuntu桌面上都遇到同样的错误 所附代码包含提取的类和示例数据。欢迎任何评论 我的平台是Ubuntu 17.10、Python 3.6.3和Raspberry Pi(Raspbian)Linux PSensor 4.9.59-v7+#1047 SMP Sun 10月29日12:19:23 GMT 2017 armv7l GNU/Linux、Python 3.5.3 在Ubuntu上开发IntelliJ IDEA *带有错误的代码如下*Python matplotlib MAXTICKS,matplotlib,python-3.6,Matplotlib,Python 3.6,你好 我在一个包含7个变量和42个数据元素的数据集上得到一个错误“Overses Locator.MAXTICKS”。我让代码在一个不遵循面向对象设计的程序中工作。我正在将应用程序转换为基于GUI的应用程序。我创建了一个类并移动了代码,从那以后,它一直抛出“RuntimeError:Locator试图从729937.416667到733955.541667:Overses Locator.MAXTICKS生成32146个刻度”我在我的Raspberry Pi和我的Ubuntu桌面上都遇到同样的错
import os
import sys
import math
import time
import queue
import shutil
import sqlite3
import datetime
import threading
import subprocess
import tkinter as tk
import random
# Imports required for graphing and animation
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
from matplotlib import dates
# import pydevd
# pydevd.settrace('E6500', port=35550, stdoutToServer=True, stderrToServer=True)
class GraphHighResData:
def __init__(self, **kwargs):
self.graph_time = {1: 736766.3923638267, 2: 736766.3924804361, 3: 736766.39259627, 4: 736766.3927130954,
5: 736766.3928300098, 6: 736766.392950463, 7: 736766.3930666025, 8: 736766.393182508,
9: 736766.3932990318, 10: 736766.3934159958, 11: 736766.3935324071, 12: 736766.3936481519,
13: 736766.3937671528, 14: 736766.3938833614, 15: 736766.3939997947, 16: 736766.3941165558,
17: 736766.3942329598, 18: 736766.3943496092, 19: 736766.3944654141, 20: 736766.3945822782,
21: 736766.3946988309, 22: 736766.3948209379, 23: 736766.3949371425, 24: 736766.3950537147,
25: 736766.3951707256, 26: 736766.3952868865, 27: 736766.3954027233, 28: 736766.3955201278,
29: 736766.3956363278, 30: 736766.3957529722, 31: 736766.3958699458, 32: 736766.3959858529,
33: 736766.3961021379, 34: 736766.3962191116, 35: 736766.3963360166, 36: 736766.3964528549,
37: 736766.3965698254, 38: 736766.3966866663, 39: 736766.3968026235, 40: 736766.3969192731,
41: 736766.3970411472, 42: 736766.3971574705}
self.graph_buffer = [{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:25:00',
'Temp': 69.8, 'TimeDiff': 10.042438983917236, 'TimeStat': 1520958300.234634, 'CCD': 57.7,
'TargetTemp': 77.79, 'Pressure': 13.2193},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 43.0, 'PrimaryKey': '2018:03:13-09:25:10',
'Temp': 69.8, 'TimeDiff': 10.075046062469482, 'TimeStat': 1520958310.30968, 'CCD': 58.1,
'TargetTemp': 77.69, 'Pressure': 13.1291},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:25:20', 'Temp': 69.8, 'TimeDiff': 10.008047103881836, 'TimeStat': 1520958320.317727, 'CCD': 58.1, 'TargetTemp': 77.69, 'Pressure': 13.1291},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:25:30', 'Temp': 69.8, 'TimeDiff': 10.093719005584717, 'TimeStat': 1520958330.411446, 'CCD': 58.2, 'TargetTemp': 77.69, 'Pressure': 13.2193},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:25:40', 'Temp': 69.8, 'TimeDiff': 10.101396799087524, 'TimeStat': 1520958340.512843, 'CCD': 58.3, 'TargetTemp': 77.69, 'Pressure': 13.1742},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:25:50', 'Temp': 69.8, 'TimeDiff': 10.407163143157959, 'TimeStat': 1520958350.920006, 'CCD': 58.4, 'TargetTemp': 77.1, 'Pressure': 12.9938},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:26:00', 'Temp': 69.8, 'TimeDiff': 10.034451007843018, 'TimeStat': 1520958360.954457, 'CCD': 58.5, 'TargetTemp': 77.69, 'Pressure': 13.084},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:26:10', 'Temp': 69.8, 'TimeDiff': 10.014230012893677, 'TimeStat': 1520958370.968687, 'CCD': 58.4, 'TargetTemp': 77.69, 'Pressure': 13.1291},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:26:21', 'Temp': 69.8, 'TimeDiff': 10.06765604019165, 'TimeStat': 1520958381.036343, 'CCD': 58.8, 'TargetTemp': 77.79, 'Pressure': 13.1742},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:26:31', 'Temp': 71.6, 'TimeDiff': 10.10568881034851, 'TimeStat': 1520958391.142032, 'CCD': 59.0, 'TargetTemp': 77.79, 'Pressure': 13.2193},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:26:41', 'Temp': 69.8, 'TimeDiff': 10.057940006256104, 'TimeStat': 1520958401.199972, 'CCD': 59.1, 'TargetTemp': 77.79, 'Pressure': 13.1291},
{'Sensor2': 75.009, 'Sensor1': 75.009, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:26:51', 'Temp': 69.8, 'TimeDiff': 10.000355005264282, 'TimeStat': 1520958411.200327, 'CCD': 59.4, 'TargetTemp': 77.59, 'Pressure': 12.8133},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 43.0, 'PrimaryKey': '2018:03:13-09:27:01', 'Temp': 69.8, 'TimeDiff': 10.28167200088501, 'TimeStat': 1520958421.481999, 'CCD': 59.7, 'TargetTemp': 77.79, 'Pressure': 13.1742},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 45.0, 'PrimaryKey': '2018:03:13-09:27:11', 'Temp': 69.8, 'TimeDiff': 10.040425062179565, 'TimeStat': 1520958431.522424, 'CCD': 59.9, 'TargetTemp': 77.79, 'Pressure': 13.1742},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:27:21', 'Temp': 69.8, 'TimeDiff': 10.059844970703125, 'TimeStat': 1520958441.582269, 'CCD': 60.1, 'TargetTemp': 77.79, 'Pressure': 12.9486},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:27:31', 'Temp': 69.8, 'TimeDiff': 10.088149070739746, 'TimeStat': 1520958451.670418, 'CCD': 60.4, 'TargetTemp': 77.98, 'Pressure': 13.1291},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 43.0, 'PrimaryKey': '2018:03:13-09:27:41', 'Temp': 71.6, 'TimeDiff': 10.057312965393066, 'TimeStat': 1520958461.727731, 'CCD': 60.6, 'TargetTemp': 77.69, 'Pressure': 13.1742},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:27:51', 'Temp': 69.8, 'TimeDiff': 10.078504085540771, 'TimeStat': 1520958471.806235, 'CCD': 60.9, 'TargetTemp': 77.79, 'Pressure': 13.1742},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:28:01', 'Temp': 69.8, 'TimeDiff': 10.005539894104004, 'TimeStat': 1520958481.811775, 'CCD': 61.6, 'TargetTemp': 77.79, 'Pressure': 13.2645},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:28:11', 'Temp': 71.6, 'TimeDiff': 10.09705901145935, 'TimeStat': 1520958491.908834, 'CCD': 61.3, 'TargetTemp': 77.69, 'Pressure': 13.0389},
{'Sensor2': 76.526, 'Sensor1': 75.519, 'Humidity': 45.0, 'PrimaryKey': '2018:03:13-09:28:21', 'Temp': 69.8, 'TimeDiff': 10.070152044296265, 'TimeStat': 1520958501.978986, 'CCD': 61.5, 'TargetTemp': 78.08, 'Pressure': 13.1742},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 45.0, 'PrimaryKey': '2018:03:13-09:28:32', 'Temp': 69.8, 'TimeDiff': 10.55004596710205, 'TimeStat': 1520958512.529032, 'CCD': 61.7, 'TargetTemp': 77.79, 'Pressure': 13.1291},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:28:42', 'Temp': 69.8, 'TimeDiff': 10.040081977844238, 'TimeStat': 1520958522.569114, 'CCD': 61.7, 'TargetTemp': 77.69, 'Pressure': 13.1291},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 45.0, 'PrimaryKey': '2018:03:13-09:28:52', 'Temp': 69.8, 'TimeDiff': 10.071845054626465, 'TimeStat': 1520958532.640959, 'CCD': 61.9, 'TargetTemp': 77.79, 'Pressure': 13.1291},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:29:02', 'Temp': 71.6, 'TimeDiff': 10.109732866287231, 'TimeStat': 1520958542.750692, 'CCD': 61.5, 'TargetTemp': 77.79, 'Pressure': 13.0389},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:29:12', 'Temp': 71.6, 'TimeDiff': 10.036301136016846, 'TimeStat': 1520958552.786993, 'CCD': 61.9, 'TargetTemp': 77.79, 'Pressure': 13.084},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:29:22', 'Temp': 71.6, 'TimeDiff': 10.008300065994263, 'TimeStat': 1520958562.795293, 'CCD': 61.9, 'TargetTemp': 77.79, 'Pressure': 13.1291},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:29:32', 'Temp': 69.8, 'TimeDiff': 10.143747806549072, 'TimeStat': 1520958572.939041, 'CCD': 62.0, 'TargetTemp': 77.79, 'Pressure': 13.1742},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:29:42', 'Temp': 71.6, 'TimeDiff': 10.039679050445557, 'TimeStat': 1520958582.97872, 'CCD': 62.0, 'TargetTemp': 78.08, 'Pressure': 13.1742},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:29:53', 'Temp': 69.8, 'TimeDiff': 10.078082084655762, 'TimeStat': 1520958593.056802, 'CCD': 62.1, 'TargetTemp': 77.69, 'Pressure': 13.1291},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 43.0, 'PrimaryKey': '2018:03:13-09:30:03', 'Temp': 69.8, 'TimeDiff': 10.106514930725098, 'TimeStat': 1520958603.163317, 'CCD': 62.0, 'TargetTemp': 77.69, 'Pressure': 13.2193},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 43.0, 'PrimaryKey': '2018:03:13-09:30:13', 'Temp': 69.8, 'TimeDiff': 10.014378070831299, 'TimeStat': 1520958613.177695, 'CCD': 61.8, 'TargetTemp': 77.79, 'Pressure': 12.9938},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:30:23', 'Temp': 69.8, 'TimeDiff': 10.047011852264404, 'TimeStat': 1520958623.224707, 'CCD': 61.8, 'TargetTemp': 77.79, 'Pressure': 13.1291},
{'Sensor2': 76.025, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:30:33', 'Temp': 69.8, 'TimeDiff': 10.10653305053711, 'TimeStat': 1520958633.33124, 'CCD': 61.9, 'TargetTemp': 77.69, 'Pressure': 13.1742},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:30:43', 'Temp': 69.8, 'TimeDiff': 10.100595951080322, 'TimeStat': 1520958643.431836, 'CCD': 61.8, 'TargetTemp': 77.79, 'Pressure': 13.1742},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:30:53', 'Temp': 69.8, 'TimeDiff': 10.094821214675903, 'TimeStat': 1520958653.526657, 'CCD': 61.7, 'TargetTemp': 78.18, 'Pressure': 13.1291},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:31:03', 'Temp': 69.8, 'TimeDiff': 10.106254816055298, 'TimeStat': 1520958663.632912, 'CCD': 61.6, 'TargetTemp': 77.79, 'Pressure': 13.1742},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:31:13', 'Temp': 71.6, 'TimeDiff': 10.095057010650635, 'TimeStat': 1520958673.727969, 'CCD': 61.6, 'TargetTemp': 77.79, 'Pressure': 13.2193},
{'Sensor2': 75.009, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:31:23', 'Temp': 69.8, 'TimeDiff': 10.018701076507568, 'TimeStat': 1520958683.74667, 'CCD': 61.6, 'TargetTemp': 77.79, 'Pressure': 12.9486},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:31:33', 'Temp': 71.6, 'TimeDiff': 10.07852292060852, 'TimeStat': 1520958693.825193, 'CCD': 61.6, 'TargetTemp': 77.79, 'Pressure': 13.1742},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:31:44', 'Temp': 69.8, 'TimeDiff': 10.529932022094727, 'TimeStat': 1520958704.355125, 'CCD': 61.6, 'TargetTemp': 77.69, 'Pressure': 13.2193},
{'Sensor2': 75.519, 'Sensor1': 75.519, 'Humidity': 44.0, 'PrimaryKey': '2018:03:13-09:31:54', 'Temp': 69.8, 'TimeDiff': 10.050326108932495, 'TimeStat': 1520958714.405451, 'CCD': 61.6, 'TargetTemp': 77.79, 'Pressure': 13.1742}]
# Define variables need for SQLite access here
self.start_opt = {}
for key, value in kwargs.items():
self.start_opt[key] = value
self.db_file = self.start_opt["dbName"]
self.db_table = self.start_opt["dbTable"]
self.debug_flag_1 = int(self.start_opt["DebugLevel"]) & 1
self.debug_flag_2 = int(self.start_opt["DebugLevel"]) & 2
self.debug_flag_3 = int(self.start_opt["DebugLevel"]) & 4
self.debug_flag_4 = int(self.start_opt["DebugLevel"]) & 8
self.total_render_freq = self.start_opt["RenderFreq"]
self.total_buffer_size = 0
self.graph_flag = False
self.total_rec = 0
self.graph_thread_active = False
self.db_rec = {"TimeStat": "", "TimeDiff": 0, "Temp": 0, "Humidity": 0, "Sensor1": 0,
"Sensor2": 0, "CCD": 0, "Pressure": 0, "TargetTemp": 0, "PrimaryKey": ""}
self.db_rec_type = {"TimeStat": "Date", "TimeDiff": "Numeric", "Temp": "Numeric", "Humidity": "Numeric",
"Sensor1": "Numeric", "Sensor2": "Numeric", "CCD": "Numeric", "Pressure": "Numeric",
"TargetTemp": "Numeric", "PrimaryKey": "Text"}
if self.debug_flag_2:
print("In GraphHighResData:{}".format(self.start_opt))
#
self.fig, self.ax1 = plt.subplots()
style.use('ggplot')
plt.title("Pool Sensors: Temperature, Humidity, Sun light Intensity")
plt.autoscale(enable=False, axis='x')
plt.autoscale(enable=True, axis='y')
plt.xticks(rotation='vertical')
plt.subplots_adjust(bottom=0.18)
self.ax1.clear()
self.date_format = dates.DateFormatter("%m/%d %H:%M")
self.ax1.set_ylabel('Temperature & Humidity 0-110 *F', color='g')
self.ax1.set_ylim(0, 110, auto=False)
self.ax1.xaxis.axis_date("US/Pacific")
self.ax1.xaxis.set_major_locator(dates.HourLocator(interval=3))
self.ax1.xaxis.set_minor_locator(dates.HourLocator(interval=1))
self.ax1.xaxis.set_major_formatter(self.date_format)
# self.temp_view = dates.date2num(timeDV) dates.num2date
self.low_res_file = self.start_opt["HResImage"]
self.high_res_file = self.start_opt["LResImage"]
def animate(self):
pass
def graph_block(self):
if self.debug_flag_2:
print("PSensorV2: Graph Block {}".format(self.graph_buffer))
#
record_cnt = 0
for rec_in_buffer in self.graph_buffer:
record_cnt = record_cnt + 1
temp_time = datetime.datetime.fromtimestamp(rec_in_buffer["TimeStat"])
self.graph_time[record_cnt] = dates.date2num(temp_time)
if self.debug_flag_2:
print("PSensorV2: Get Time {}:{}\n({})({})".format(record_cnt, rec_in_buffer,
self.graph_time[record_cnt], temp_time))
plt.ion()
buff_size = len(self.graph_buffer)
temp_rec = {}
ccd_data = {}
target_temp = {}
sensor1 = {}
sensor2 = {}
temp = {}
humid = {}
pressure = {}
if self.debug_flag_2:
print("PSensorV2: Pre-Animate ({})\n{}\n{}".format(buff_size, self.graph_time, self.graph_buffer))
for i in range(buff_size):
temp_rec = self.graph_buffer[i]
ccd_data[i] = temp_rec["CCD"]
target_temp[i] = temp_rec["TargetTemp"]
sensor1[i] = temp_rec["Sensor1"]
sensor2[i] = temp_rec["Sensor2"]
temp[i] = temp_rec["Temp"]
humid[i] = temp_rec["Humidity"]
pressure[i] = temp_rec["Pressure"]
self.ax1.plot(xdata=self.graph_time, ydata=ccd_data, c='b', ls='--', label='Sun Intensity')
self.ax1.plot(xdata=self.graph_time, ydata=target_temp , c='y', ls='.', label='Target Temp')
self.ax1.plot(xdata=self.graph_time, ydata=sensor1, c='c', label='Inlet Temp')
self.ax1.plot(xdata=self.graph_time, ydata=sensor2, c='r', label='Outlet Temp')
self.ax1.plot(xdata=self.graph_time, ydata=temp, c='g', label='System Temp')
self.ax1.plot(xdata=self.graph_time, ydata=humid, c='g', ls='-.', label='Humidity')
self.ax1.plot(xdata=self.graph_time, ydata=pressure, c='b', ls=':', label="Pressure")
plt.legend(fontsize='x-small', loc='upper left')
# animation.FuncAnimation(self.fig, self.animate, interval=1000, repeat_delay=5000, blit=True)
print("Show")
plt.show()
print("Save Low")
plt.savefig(self.low_res_file, dpi=600, transparent=False)
print("Save High")
plt.savefig(self.high_res_file, dpi=1200, transparent=False)
# plt.show()
print("Draw")
plt.draw()
return 0
# ###############
startup_options = {'RenderFreq': 5, 'HResImage': '/home/jcfowler/Desktop/HResImage.jpg', 'LoopWaitTime': 15,
'dbName': '/mnt/home/DB/PoolHighResTemps.db', 'TotalWriteCnt': 30,
'DebugLevel': '3', 'dbTable': 'HighResTemps', 'TotalCellCnt': 5760,
'LResImage': '/home/jcfowler/Desktop/LResImage.jpg'}
# Start Test Program
graph_data = GraphHighResData(**startup_options)
test_object=graph_data.graph_block()
time.sleep(60)
matplotlib在不喜欢接收到的数据时抛出Locator.MAXTICKS错误。我简化了代码,以获取数据结构并将其复制到一个麻木的数组中,它将绘制数据。当我将代码移动到我的GUI应用程序时,它将在第一次显示图形,并在随后的过程中失败。每次都抛出MAXTICKS错误
我从GUI中删除了所有matplotlib代码,并将其替换为pygal中的十行代码,并将图形保存到临时文件中。然后按下按钮显示该文件。每次都有效。越简单越好 如果你想在这里得到帮助,你需要提供帮助。什么是
/home/jcfoller/Desktop/HResImage.jpg
?这是打印图形中预期保存的图像。附加的代码将重现该问题。如果它在另一个系统上工作,那么问题就出在我的Ubuntu和Raspberry Pi设备上。不,你肯定有代码问题,而不是系统问题。但是您应该提供可以在另一个系统上运行的。就目前情况而言,我需要花半个小时才能真正理解绘图应该显示的内容,而问题可以用一行左右的代码来解决。