2016-07-08 9 views
0

Jedes Mal, wenn ich die display_data Funktion ausführen (wenn es Daten gibt, nach dem erfolgreichen Beantwortung mindestens eine calculation_game Frage ausgeführt werden) Ich erhalte eine Fehlermeldung, die sagt:Ausgabe Einstellung matplot Punkte Farbe und Form

"ValueError: to_rgba: Invalid rgba arg "o" 
to_rgb: Invalid rgb arg "o" 
could not convert string to float: 'o'" 

Wenn ich laufe der Code ohne das "o", um die Form der Punkte zu definieren, funktioniert es gut und zeigt blaue Punkte an. Einzige Sache ist, dass ich Formen wie "o" und "v" definieren kann, weil das Diagramm Daten von mehreren Listen zeigt, wenn es fertig ist. Irgendwelche Ideen?

HINWEIS:

Es fehlen Funktionen unten. Ich habe sie hier entfernt, weil sie für die Frage nicht benötigt werden.

import random 
from random import randint 
import time 
import math 
import matplotlib.pyplot as plt 


# Number of problems for each practice/real round 
practice_round = 0 
real_round = 3 

main_record = [] 
CALC_RECORD = [] 

# (1) Calculation Game --------------------------------------------------------- 
'''Calculation game is a math game''' 
def calculation(): 
    response_time = None 
    # Determine the min and max calculation values 
    min_calculation_value = 1 
    max_calculation_value = 10 
    # Generate the problems 
    print('\nSolve the following problem:') 
    a = random.randint(min_calculation_value, max_calculation_value) 
    b = random.randint(min_calculation_value, max_calculation_value) 
    problem_type = random.randint(1,2) 
    if problem_type == 1: 
     answer = a * b 
     print(a, '*', b) 
    elif problem_type == 2: 
     answer = a % b 
     print(a, '%', b) 
    # Get the user's answer determine what to do if correct 
    start_time = time.time() 
    user_answer = input('\nEnter your answer: ') 
    end_time = time.time() 
    if user_answer == str(answer): 
     response_time = end_time - start_time 
     print('You are correct!') 
    elif user_answer != str(answer): 
     print('Oops, you are incorrect.') 
    # Return game id, start time, and response time 
    return("calculation", start_time, response_time) 

def calculation_game(): 
    record = [] 
    # Generate two problems for a practice round 
    print("\nLet's begin with 2 practice problems.") 
    for i in range (practice_round): 
     print('\nPractice Problem', i + 1, 'of', practice_round) 
     calculation() 
    # Generate 10 problems for a real, recorded round 
    print("\nNow let's try it for real this time.") 
    for i in range (real_round): 
     print('\nProblem', i + 1, 'of', real_round) 
     # Append records for each iteration 
     record.append(calculation()) 
    main_record.extend(record) 
    CALC_RECORD.extend(record) 
    return record 

# (5) Display Data ------------------------------------------------------------- 
def display_data(): 
    plt.ylabel('Time Per Question') 
    plt.xlabel('Round Played') 
    CALC_RECORD.sort(key=lambda record:record[1]) 
    calc_time = [t[2] for t in CALC_RECORD if t[0] =='calculation' and t[2] != None] 
    alist=[i for i in range (len(calc_time))] 
    if len(calc_time) >0: 
     print (calc_time) 
     x = alist 
     y = calc_time 
     plt.scatter(x, y, c="bo") 
     plt.show(block=True) 
    main_menu() 


# (6) Save Progress ------------------------------------------------------------ 



# (7) Load Data ---------------------------------------------------------------- 



# (8) Quit Game ---------------------------------------------------------------- 

def quit_game(): 
    print('\nThank you for playing!') 

# Main Menu -------------------------------------------------------------------- 

def menu(): 
    print("\nEnter 1 to play 'Calculation'") 
    print("Enter 2 to play 'Binary Reader'") 
    print("Enter 3 to play 'Trifacto'") 
    print("Enter 4 to view your statistics") 
    print("Enter 5 to display data") 
    print("Enter 6 to save your progress") 
    print("Enter 7 to load data") 
    print("Enter 8 to quit the game") 

def main_menu(): 

    print('Welcome!') 
    user_input = '' 
    while user_input != '8': 
     menu() 
     user_input = input('\nWhat would you like to do? ') 
     if user_input == '1': 
      calculation_game() 
     if user_input == '2': 
      binary_reader_game() 
     if user_input == '3': 
      trifacto_game() 
     if user_input == '4': 
      display_statistics() 
     if user_input == '5': 
      display_data() 
     if user_input == '8': 
      quit_game() 

main_menu() 
+1

Sie fügen 123 Zeilen Code und doch lassen Sie helfend die Zurückverfolgungs die Zeilennummer aus gab Sie ausfindig ** genau, wo Ihre Fehler aufgetreten **? Alter! Danke. :/ –

+0

Ich weiß nicht 'matplotlib', aber es sieht aus wie' plt.scatter (x, y, c = 'bo') 'das Argument c ist [Farben] (http://matplotlib.org/api/collections_api .html # matplotlib.collections.Collection.set_color), die aus Tupeln bestehen soll. Anscheinend versteht es nicht, was du mit 'bo' meinst. –

+0

Mit Blick auf die Dokumentation (http://matplotlib.org/users/pyplot_tutorial.html) haben sie die Farbe und Form wie meine formatiert. Ich bin mir nicht sicher, warum es schwer ist. –

Antwort

0

Verstanden, musste nur die c entfernen = Teil von plt.scatter(x, y, c="bo")

Verwandte Themen