【问题标题】:Syntax Error when typing colors = matplotlib.pyplot.rcParams['axes.prop_cycle'].by_key()['color']键入颜色时出现语法错误 = matplotlib.pyplot.rcParams['axes.prop_cycle'].by_key()['color']
【发布时间】:2021-06-12 04:28:24
【问题描述】:

不断收到语法错误;

colors = matplotlib.pyplot.rcParams['axes.prop_cycle'].by_key()[
            'color']

完整代码:

########### 1. Dependencies
import time
import math
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.animation
import matplotlib.pyplot as plt
import scipy
from matplotlib.figure import Figure
from scipy.signal import filtfilt

# matplotlib.use ('TkAgg') # 3 FPS
import brainflow
from brainflow.board_shim import BoardShim, BrainFlowInputParams, LogLevels, BoardIds
from brainflow.data_filter import DetrendOperations, DataFilter, FilterTypes, AggOperations, WindowFunctions
import scipy.signal as sig


class CytonStream(object):
    def __init__(self):
        ########### 2. Create Variables for Holding the Stream
        self.display_window = DataFilter.get_nearest_power_of_two(500) # Attribute, DataFilter class contains methods for signal processing
        self.data = [0]*self.display_window 
        self.fft = [[0], [0]] # This is for the second "graph" of the Mathplotlib

        ########### 3. Connecting to Cyton Board
        BoardShim.enable_dev_board_logger () 
        params = BrainFlowInputParams()
        board_id = BoardIds.CYTON_BOARD
        self.sample_rate = BoardShim.get_sampling_rate(board_id)
        self.board_channel = BoardShim.get_eeg_channels(board_id)[0]
        params.serial_port = '/dev/cu.usbserial-DM03H7UU' # Port
        board_id = 0 #BoardIds.CYTON_BOARD(0)
        board = BoardShim(board_id, params) # Board Stream Object
        board.prepare_session() # Prepare the session
        # board.start_stream () # use this for default options
        board.start_stream() #Create streaming thread 
        self.board = board
        
        ########### 4. Creating Matplotlib Parmeters/ Plots
        self.fig, axes = plt.subplots(3, 1, figsize=(11,7)
        colors = matplotlib.pyplot.rcParams['axes.prop_cycle'].by_key()[
            'color']
        
        ##### Set the Axes
        self.wave_ax = axes[0] #Location 1
        
        ##### Set Title
        self.wave_ax.set_title("Cyton Waveform") #Title 1

【问题讨论】:

    标签: python matplotlib syntax syntax-error


    【解决方案1】:

    colors = ... 行上方的行中缺少右括号。

            #                                                 ↓ this one
            self.fig, axes = plt.subplots(3, 1, figsize=(11,7))
            colors = matplotlib.pyplot.rcParams['axes.prop_cycle'].by_key()[
                'color']
    

    【讨论】:

    • 非常感谢。我不知道我是怎么错过的。我今天正在使用一个新的编辑器,所以它甚至没有告诉我。
    猜你喜欢
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多