Python's simple code: a two-day program for drawing function images (scatterplots) of the liver (super-detailed explanations and source code that can also be read by Chinese cabbage)

Keywords: Python

[Original Creator: Well-off 2021]

The program (toy) basically supports any function in the normal function and math module, the specific operation instructions are shown in the effect diagram below. Bloggers have limited abilities (so beginners can read my code 100 percent), and the finished product (absolute originality) takes two days to burst the liver, which has changed a lot   BUG, the finished products now have few functions, but should not   BUG, if there are any errors or other   BUG, or if you have any good suggestions, please point out and leave your name in the comments area (so that I can go to see you for tea).

The blogger is only a freshman. I only learned Python for two months when I wrote this blog, and Python is only my hobby, so my ability is limited. If you don't write well, please don't like it. Thank you!

1. Display of finished product effect

1. Procedure description section (similar to instructions)

2. Select Framework Section

Optional items are: coordinate point style, function, zoom, and bounds.

3. Main part of function image

(1) Function: f(x)=x (bigger picture, bad screenshot, split in half)

The instructions above the image are: function, calculation range (range in parentheses), scale, calculation accuracy.

The following instructions for the image are: actual coordinate values.

The left side of the image is the ordinate coordinate when the zoom is 1.

(2) Function: f(x)=sin(x) (where coordinate point style changed to option 2'@')

(3) Function: f(x)=tan(x) (Custom coordinate point style is'A')

4. Data analysis (taking function: f(x)=x as an example)

Data analysis is only image-based analysis, not data outside the image.

That's the basic effect. Wouldn't it be great to see such a program (toy)? Let's start teaching!

2. Analytical Teaching Section

Prerequisite knowledge: (that is, I don't want to talk much, but still talk)

1. Python exceptions and errors: try...except...else...finally   Usage (else and finally are unnecessary and not used in this program). If you want to know something about it now, stamp it hard: Python3 Errors and Exceptions|Newbie Tutorial

2. Python judgment statement: if...elif...else usage, want to know the comrades go crazy: Python if Statement|Newbie Tutorial

3. Python Loop Statement: while 1:... break usage, similarly hit: Python While Loop Statement|Newbie Tutorial

(1) Explanatory section

[Explain how to use the program to make it easier for users to use the program (or toys)]

Source code:

###########################################>>> Scatter Coordinate Graph Source Code <<<###########################################
print('''\033[33m
============================================================================================================
 [Scatter coordinate map·Instructions for Use) Author: Well-off Version: 3.34   Update date date: 2021.12.02
 1,The coordinate point style will be fixed after the first input, defaulting to+,That is, enter any non-option value;
 2,Custom coordinate point styles are not recommended and may result in image errors.
 3,The input function expression should be x Is an independent variable and defaults to an empty function;
 4,Zoom in refers to the magnification of zoom in or out. It must be a number greater than zero, defaulting to 1, less than 1 to zoom in, greater than 1 to zoom in.
 5,Bounds 1 and 2 refer to the scope of the function(Automatically rounds to zero),The default values are-30 And 30;
 6,The left ordinate of the function image is the one with a scale of 1.
 7,The lower right corner of the function image[x]Refers to the actual coordinates of the location, with a scale of 1 x=30;
 8,The default horizontal and vertical coordinate size given by the function image is-30~30;
 9,The minimum value in image data analysis is not an exact value, but an approximation value. The minimum precision of image data calculation is: coordinate value/Scale value;
10,The bell rings when there is a problem.
============================================================================================================\033[0m''')

Code parsing:

(1) Here in the print function, three quotes ('') are used to make the text output as we want, with three quotes at the beginning and end of the text.

(2) Neodymium at the beginning and at the end controls the color of the output text. Neodymium means that the output text behind it is changed to yellow. Neodymium means that the text behind it is changed to the default color, that is, there is no additional color effect. Note that Neodymium 3 [33m is to change the color of all the text behind it, including the text output by other print functions, so at the end of the output text of this print function, we want to add 3[0m so that the output text behind it is unaffected.

Additional instructions:

(1) That version number is real, not casual, three big changes, many small changes, it is a bit of BUG stacked up! Thank you for BUG! BUG always drips!

(2) If you want to know more about how to set the output text color and style, here is the quick hammer: How Python outputs colored text methods _u013934107 Blog-CSDN Blog

(3) We suggest that you take a look at the above instructions first.

(2) Selection Framework

[Force user to set all options (parameters)]

Source 1:

################################################## Selection Frame ##################################################
from math import *
print('[1]o  [2]@  [3]custom');styleinput = input('Coordinate point style:')
style = 'o' if styleinput=='1' else '@' if styleinput=='2' else '+'
if styleinput =='3':style = input('Custom coordinate point style:')
if style == '+':print('\033[36m Default to+\033[0m')

Code parsing one:

(1) All functions of the math module are introduced (all represented by *), which makes it easy to expand the support of subsequent input functions (almost all functions are supported).

(2) The print function on the third line prints the text to tell the user what to choose and how to choose the coordinate point style, then records the user's input value with the input function and assigns it to the variable styleinput  .

(3) The fourth line is the built-in structure of the if statement, which is an abbreviation of the if statement

This means that if the variable styleinput equals string 1, the variable style (the form in which we store the style with this variable) is assigned the string o. If the variable styleinput equals string 2, the variable style is assigned the string @. In the rest of the cases, the variable style is assigned the string +, which is the default value.

(4) If a comrade asks, then if a variable   Styleinput equals string 3, variable   Style   Wasn't it assigned string + yet? Yes, it's absolutely correct, but what about the changes that follow? The fifth line determines if the variable styleinput is string 3, and if so, the variable style   Is re-assigned to the value of the input function, even if the user defined the value.

(5) Add Default Value Description

The last line, if the user enters a value other than string 1, 2, 3, or nothing else, follows the previous logic and the variable style is assigned a string+, which is the default value, at which point a line of text is printed to tell the user that it is now the default value. This line of text is colored for distinction and aesthetics.

Additional Note 1:

(1) Source code executes only once and does not loop through (as compared to later code).

(2) In this article I write, you can find the simplified form of if statement, the explanation of if embedded structure, transmission matrix:

Refinement of Python Code_ Well-off 2021 Blog-CSDN Blog

Source 2:

while 1:
    while 1:
        func = input('Function: f(x) = ')
        if func == '':func = 'None';print('\033[36m Empty function by default\033[0m')
        try:f = eval('lambda x:'+func);break
        except:print('\033[31m Syntax error! Please re-enter the function!\033[0m','\a')
    while 1:
        correct = input('Scaling:')
        if correct == '':correct = '1';print('\033[36m Default 1\033[0m');break
        try:useless = log(float(correct));break
        except:print('\033[31m Syntax error! Please re-enter the zoom!\033[0m','\a')
    while 1:
        limit1 = input('Limit 1:')
        if limit1 == '':limit1 = '-30';print('\033[36m Default to-30\033[0m');break
        try:useless1 = float(limit1);break
        except:print('\033[31m Syntax error! Please re-enter bounds 1!\033[0m','\a')
    while 1:
        limit2 = input('Limit 2:')
        if limit2 == '':limit2 = '30';print('\033[36m Default is 30\033[0m');break
        try:useless2 = float(limit2);break
        except:print('\033[31m Syntax error! Please re-enter Limit 2!\033[0m','\a')

Code parsing two:

(1)   While 1:... Break usage

Actually, this 1 can be changed to any Boolean value other than Flase   The Boolean values of values such as number 0, empty list [], and so on, are Flase and the loop executes as long as they are not. However, unlike normal while loops, normal while loops generally have conditions that are unsuccessful and stop when they are unsuccessful, but while 1 never judges Flase, so you must have a break statement in the body of while 1 to stop the loop. However, it does not mean that the loop must be terminated. Sometimes the effect some programs want is to keep the loop running.

In this code: the first while is a big loop, followed by whiles at the same level. Each small loop has a break statement to terminate itself under specific conditions. The big loop does not stop in this code (because the total code is too long to show here). For the time being, let's remember that it is not stopped, and write down as   UNSTOP, wait until you see the marker again later, and come back to see it for your understanding.

(2)   Try... Except statement

The explanation for this is very simple. Statements between try and except are tried   Statement detection for errors (syntax error SyntaxError, name error)   NameError, type error   TypeError   If an error occurs, the following code will continue to execute, but the statement following except will not execute, because the statement following except will execute only after try detects an error. If try detects an error, the execution of the program will end directly at the first error code, instead of the following code. And go directly to except to execute the code that follows. If except has indicated some or some specific type of error, the statement after except will only be executed if those specific errors are generated in the code between try and except. However, there is not so much to consider here. We don't want any kind of error here, so we don't need to decide whether a particular error has occurred or not. We just need to decide if an error has occurred.

In this code: Let's start with the statement in the first small loop, where the input function assigns the user-entered function to the variable func as a string, then the if statement determines if the variable func is an empty character (the user does not enter anything and presses Enter directly), and if so, assigns the variable func to the default value string.   None (you don't have to use None here, just for our own sake, meaning empty functions, that is, nothing), and print the appropriate information to the user to tell them that the function is the default value. Once you've done that, you can use the try...except statement to catch the error. Here you use the lambda function to convert the function string entered by the user into a real function (string form), and then use the eval function to convert the function entered by the user (string form) into a real mathematical expression. Because the user may enter values that the eval function cannot recognize (we don't know what it is) or there is a problem with the lambda function, try to catch errors. If there are no errors, the program will execute normally and the break statement will execute normally, so this small loop will stop immediately and if any errors occur, After the eval function is executed, the subsequent break is not executed (because the eval function is already wrong), but goes directly to the except statement and executes the print function to print out some information that tells the user that the function entered is problematic, and rings (the escape character\a does), then the great thing is: there is no break in this little loop. So it loops until the user enters the correct function, which the eval function can parse.

(3) Small circulation behind

In the second small loop, the only difference from the first is that the code behind the try statement is different. What is behind the try statement depends on our requirements. Here, the scale is entered, which should be a real number greater than zero mathematically and in our definition. So here's the second great thing: we store a judgment with a useless variable, useless, where float determines if correct is a numeric string, only if the input is scaled to a string that meets the criteria (and later changes its type to a number). log then determines if the number represented by this number string is greater than zero, and there will be no errors unless it is valid at the same time, that is, the number represented by correct meets the requirements. Once this assignment statement is wrong, try will catch it, and the process will be the same as the first loop. In the third and fourth little loops, the boundaries are just numbers, so floats are all that's needed, and the rest are the same.

Additional Note 2:

(1) More information about eval functions, portal: Python eval() function|novice bird tutorial

(2) More about lambda anonymous functions, Transport Points: Anonymous function - Liao Xuefeng's official website

(3) For an escape character in this print function\a: I can only say that when I print it for nothing (it won't really print out), the computer will sound a reminder.

(4) Some comrades may ask: What's the use of your variables being strings? Don't worry, here's the code to solve this problem.

Source Code 3: (All lines have an extra indent under the big loop)

    correct = eval(correct);limit1 = eval(limit1);limit2 = eval(limit2)
    if limit1 > limit2 : limit1,limit2 = limit2,limit1
    a,b = int(limit1*correct),int(limit2*correct+1);print('')

Code parsing three:

(1) This first line of code should not be too explanatory.

(2) Force the size relationship between limit1 and limit 2 to be determined (since these two must be combined with the range function later)

The second line of code swaps the values if limit1 is greater than limit2, so limit2 is greater than or equal to limit1, and if limit1 is less than limit2, nothing happens, because that's what we want.

(3) Controlling the effect of scaling on the range function that follows

If the zoom correct is greater than 1, the image should be enlarged. Since the size box of the image does not change, the calculation accuracy in the same interval will be improved, the data calculated will be more, and the number of calculations will be more, so multiply the values of both boundaries by the zoom. Since the parameters in subsequent range functions can only be integers, the int function is used, and to calculate all the data, the large bounds are added by one (range)   Functions do not produce end values). The last two values are stored in a and b, which you will use later.

(4) The last print function prints empty characters to wrap lines, and that's all for the sake of aesthetics.

(3) Initializing the coordinate database

[Let each coordinate location have a value to store and initialize these values]

Source Code: (All lines have an extra indent under the big loop)

################################################## Initialize coordinates ##################################################
    line30= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line29= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line28= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line27= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line26= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line25= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line24= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line23= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line22= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line21= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']    
    line20= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line19= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line18= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line17= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line16= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line15= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line14= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line13= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line12= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line11= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line10= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line9 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line8 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line7 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line6 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line5 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line4 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line3 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line2 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line1 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    line0 = ['\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m',
'\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m',
'\033[31m┼\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m',
'\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m','\033[31m─\033[0m']
    fine1 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine2 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine3 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine4 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine5 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine6 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine7 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine8 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine9 = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine10= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine11= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine12= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine13= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine14= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine15= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine16= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine17= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine18= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine19= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine20= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine21= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine22= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine23= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine24= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine25= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine26= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine27= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine28= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine29= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
    fine30= [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\033[31m│\033[0m',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']

Uh... There are more than a billion points. Don't worry about this. We program apes have liver. (Actually   copy   That's it)

Code parsing:

(1) Initialize each list in order, where line represents the y>0 (y represents ordinate) part and fine represents y<0   Part (f means'negative'), but line0 is different, line0 should be initialized after x-axis initialization, so take it out separately.

(2) There are 61 lists representing 30 rows on the x-axis, 30 rows on the axis and 30 rows below the axis, and 61 corresponding horizontal coordinates. The 31st position (index 30) of each list (excluding the x-axis) is neodymium 3[31m] 3[0m, which is not much about color settings. The middle vertical line is the vertical line in the tab, which can usually be typed out as input. Then, the data for each location of the x-axis is neodymium 3[31m-3 [0m, again, the middle one is a tab. Finally, the middle one (the origin position) in the whole image is also a tab, but it's very special: the list on the x-axis is longer, so I changed lines a few times and it looks like the code you see now.

(3) What? You asked me why I added neodymium 3[31m and neodymium 3[0m] to every data in the x-axis list instead of just adding neodymium 3[31m before the first data and neodymium after the last data. [0m?? Ah, I can only say that this is a fairly easy mistake. Because when the back image is shaped, that coordinate point is also color-set. If you do not add color settings to every data on the x-axis, then assume that the function image has a calculated coordinate point exactly on the x-axis, and that coordinate point itself has color settings, then it will play Break the color setting of the original x-axis. Let's talk about the code for that coordinate point in advance, and it looks like this:'3[32m'+style+'3[0m'. Obviously, this 3[0m] will dry the following X-axis data points to the default color (if the data behind does not have a color set).

(4) Initializing the Index Library

[Easy to set up a two-dimensional list and precisely locate coordinate locations]

Source Code: (All lines have an extra indent under the big loop)

################################################## Initialize Index ##################################################
    listData = [
    fine30,fine29,fine28,fine27,fine26,fine25,fine24,fine23,fine22,fine21,
    fine20,fine19,fine18,fine17,fine16,fine15,fine14,fine13,fine12,fine11,
    fine10,fine9,fine8,fine7,fine6,fine5,fine4,fine3,fine2,fine1,
    line0,
    line1,line2,line3,line4,line5,line6,line7,line8,line9,line10,
    line11,line12,line13,line14,line15,line16,line17,line18,line19,line20,
    line21,line22,line23,line24,line25,line26,line27,line28,line29,line30]

Code parsing:

Nothing to say, there are several small lists in a large list. This index library is initialized in a bottom-up order. This order can't be wrong! The one-dimensional index of this large list can be imported to the corresponding small list (ordinate), the index of the small list, that is, the two-dimensional index (transverse coordinate) of the large list, to the data points of the corresponding row, and the combination of the two can precisely find the corresponding coordinate location.

(5) Calculation of coordinates

[Calculate the value of the function and import it to the corresponding coordinate data]

Source Code: (All lines have an extra indent under the big loop)

################################################### Calculate coordinates ###################################################
    correctlist = [];errorlist = []
    for i in range(a,b):
        if 0 <= i+30 <= 60:
            try:
                result = round(f(i/correct)*correct)
                if 0 <= result+30 <= 60:
                    listData[result+30][i+30] = '\033[32m'+style+'\033[0m'
                    correctlist.append(f(i/correct))
            except:errorlist.append(str(i/correct))

Code parsing:

(1) Create two lists, correctlist to store the correct function values and errorlist to store the wrong independent variable values, both of which are used for subsequent data analysis.

(2) The range function here uses the previous a and b values, and the integer between them is a key value for all points to be calculated. Then, because the following listData[result+30][i+30] is a two-dimensional list, in which both the one-dimensional index and the two-dimensional index have a range, if out of range, the list listData cannot find the corresponding value of that index, and it will make an error! So, let's first limit the range of I with if. Then try...except statements are used here to capture errors that may occur when calculating the function values (possible errors are: the independent variable values are not in the function definition domain, etc.). If there are no errors, use listData to find the corresponding coordinate location, and change the data for that location to the already determined coordinate point style (mentioned earlier), and finally, The calculated function values are also stored in the correctlist. If there is an error, put the wrong argument in the errorlist. There is no break statement in this loop for, so it will calculate all the values produced by the range function.

(3) As for this scaling problem, it is a simple second grade topic! I believe you can understand it by looking at it yourself. (Bloggers are lazy)

(6) Printing coordinate maps

[Identify some data to illustrate and print the calculated data as an image]

Source Code: (All lines have an extra indent under the big loop)

################################################## Print coordinate map ##################################################
    print('\033[34m=================================================================================================================================\033[0m')
    print('   [Function scatterplot:\033[36m f(x) = %s\033[0m (\033[36m%.1f<x<%.1f\033[0m)]   Image Range:\033[36m%.1f≤Transverse coordinates≤%.1f\033[0m   Scaling:\033[36m%.1f\033[0m   Calculating accuracy:\033[36m%.1f\033[0m'
    %(func,limit1,limit2,-30/correct,30/correct,correct,1/correct))
    print(' ==\033[32m┍───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┑\033[0m')
    print(' 30\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line30))) #30
    print(' 29\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line29))) #29
    print(' 28\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line28))) #28
    print(' 27\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line27))) #27
    print(' 26\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line26))) #26
    print(' 25\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line25))) #25
    print(' 24\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line24))) #24
    print(' 23\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line23))) #23
    print(' 22\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line22))) #22
    print(' 21\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line21))) #21
    print(' 20\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line20))) #20
    print(' 19\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line19))) #19
    print(' 18\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line18))) #18
    print(' 17\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line17))) #17
    print(' 16\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line16))) #16
    print(' 15\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line15))) #15
    print(' 14\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line14))) #14
    print(' 13\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line13))) #13
    print(' 12\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line12))) #12
    print(' 11\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line11))) #11
    print(' 10\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line10))) #10
    print('  9\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line9))) #9
    print('  8\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line8))) #8
    print('  7\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line7))) #7
    print('  6\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line6))) #6
    print('  5\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line5))) #5
    print('  4\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line4))) #4
    print('  3\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line3))) #3
    print('  2\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line2))) #2
    print('  1\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(line1))) #1
    print('  \033[31m0\033[0m\033[32m│\033[0m %s \033[32m│\033[0m'%('\033[31m─\033[0m'.join(line0))) #0
    print(' -1\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine1))) #1-
    print(' -2\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine2))) #2-
    print(' -3\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine3))) #3-
    print(' -4\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine4))) #4-
    print(' -5\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine5))) #5-
    print(' -6\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine6))) #6-
    print(' -7\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine7))) #7-
    print(' -8\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine8))) #8-
    print(' -9\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine9))) #9-
    print('-10\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine10))) #10-
    print('-11\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine11))) #11-
    print('-12\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine12))) #12-
    print('-13\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine13))) #13-
    print('-14\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine14))) #14-
    print('-15\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine15))) #15-
    print('-16\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine16))) #16-
    print('-17\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine17))) #17-
    print('-18\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine18))) #18-
    print('-19\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine19))) #19-
    print('-20\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine20))) #20-
    print('-21\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine21))) #21-
    print('-22\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine22))) #22-
    print('-23\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine23))) #23-
    print('-24\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine24))) #24-
    print('-25\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine25))) #25-
    print('-26\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine26))) #26-
    print('-27\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine27))) #27-
    print('-28\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine28))) #28-
    print('-29\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine29))) #29-
    print('-30\033[32m│\033[0m %s \033[32m│\033[0m'%(' '.join(fine30))) #30-    
    print(' ==\033[32m┕───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┙\033[0m')
    print('\033[33m Ordinate coordinates\033[0m                                                           \033[31m0\033[0m                                                 \033[33m Actual coordinates\033[0m[\033[32m%.1f\033[0m]'%(30/correct))
    print('\033[34m=================================================================================================================================\033[0m')

Isn't that much? Emperor Gan said there was no pressure. (That's not good)   copy   Yes, the liver comes out hard..)

Code Analysis:

(1) The stack of = above and below this code is just for aesthetics.

(2) The second print function prints some basic data about the image, including the function itself, the user-defined calculation range, the actual range of the image, the scale, and the calculation accuracy. Specific descriptions of these data are included in the instructions for use and will not be repeated here. If you want to ask how to calculate it, you can see the formula after the last% of the print function, so I won't talk more about it here.

(3) The second-to-last print function prints the ordinate coordinates, the 0-datum and the actual coordinates, so the calculation of these basic data is the same and will not be discussed any more. Also, to illustrate, this "ordinate" is just for aesthetics.

(4) For the two long lines up and down, the tab character'-'is also used.   Print, length is blogger's own try.

(5) The most important part is the middle part, where each list is printed symmetrically with line0 as the intermediate datum. The first number after each print is the ordinate coordinate with a scale of 1 (line0).   The number 0 sets the color), which is the initial ordinate coordinate, then the color-fixed tab, then the%s, which means to output the contents of each list as a string, then as a tab, and finally, the key part is to use the join function to join the data of each list together as strings, separated by space characters. (line0 is special, different) so that it can be output as a string! As for line0, because it represents the x-axis, it is joined at tab intervals, and the tab is colored.

Additional instructions:

(1) If you have comrades, you will be curious. Why do you want to connect with space characters? Why not connect directly? I can only say that if you don't do this, the actual proportions of the mathematically equivalent length of the horizontal and vertical coordinates here will not be equal at all   1  ! The y-axis will be much longer than the x-axis! Therefore, after many times of practice by bloggers, it is necessary to connect with space characters to achieve the desired effect. Simply put, it's for beauty!

(2) The knowledge gate for Python join functions: Python3 join() method|novice bird tutorial

(7) Data analysis

[Data analysis with computed data to give users a better understanding of the functions drawn]

Source Code: (All lines have an extra indent under the big loop)

################################################### Data analysis ###################################################
    judgelist = [];judge = 1;out = '';n = 1;judgestyle = '\033[32m'+style+'\033[0m'
    if errorlist == []:errorlist.append('None') 
    if correctlist == []:correctlist.append('0');out = '\033[31m There is an error in the function! Please check!\033[0m'+'\a';parity = 'None';n = 0;errorlist = ['All']
    if n == 1:
        for k1 in range(61):
            if judge == 0:break
            for k2 in range(61):
                if k1 != 30:
                    if listData[k1][k2]==judgestyle and (listData[60-k1][60-k2]!=judgestyle and listData[k1][60-k2]!=judgestyle):judgelist.append('0');judge = 0;break
                    elif listData[k1][k2]==judgestyle and listData[60-k1][60-k2]==judgestyle:judgelist.append('1')
                    elif listData[k1][k2]==judgestyle and listData[k1][60-k2]==judgestyle:judgelist.append('2')
                else:
                    if listData[30][k2]!=listData[30][60-k2]:judgelist.append('0');judge = 0;break
        if '0' in judgelist:parity = 'Non-odd and non-even functions'
        elif judgelist == []:parity = 'Both odd and even functions'
        elif '2' not in judgelist:parity = 'Odd function'
        elif '1' not in judgelist:parity = 'Even function'
        else :parity = 'Non-odd and non-even functions'
    print('[\033[36m Image data analysis\033[0m]   %s'%out)
    print('Maximum:\033[32m%s\033[0m'%(max(correctlist)))
    print('Minimum value:\033[32m%s\033[0m'%(min(correctlist)))
    print('Parity:\033[32m%s\033[0m'%parity)
    print('The following locations are undefined:\033[32mx=%s\033[0m'%(' x='.join(errorlist)))

Code Analysis:

(1) First, create a judgelist, judgement value, coordinate point style judgement value, and an out to output some data.   And the judgement n, there are two for loops, so let's define them as outer loops and inner loops, which are nested loops.

(2) Determine if the errorlist is empty, or if it is empty, add a string None to the errorlist  . Erorlist is empty, which means that the function is defined at all locations on the image, so add a None and output None at the last print. If it is not empty, then the last print directly uses the join function to output all the values of undefined independent variables.

(3) Determine if the correctlist is empty, and if it is empty, add a string of 0 in and set out to a string, where the output is in the appropriate location, and set parity (parity) to the string None, n to 0, and errorlist to only one string All (not to add a string None). What is this doing? The correctlist is empty, meaning that all definitions of the function do not exist in this image. That is to say, the function has errors, so to give the user a message, the out is set to the information it should have. At the same time, the parity cannot be determined, it is set to None, there is no definition anywhere, so the errorlist is set to a single string All. But not directly, because errorlist originally has all undefined independent variable values, we change it to All, just to simplify it. Anyway, there is no definition everywhere, so there is no need to output undefined independent variable values, and output All directly to tell the user that there is no definition everywhere. As for setting n to zero, that's to end the loop below (the loop below will only execute if n=0). That loop is set up to judge parity, and since there is no definition, there is no need to judge parity.

(4) Judging the parity of a function in the for loop

To judge the parity of a function, it is natural to judge whether all the points on the function image meet the requirements, so all the data should be traversed. Set the vertical and horizontal coordinates to be K1 and k2, respectively. Both values should traverse all indexes from 0 to 60, so nest the two values and use the range function to create all the indexes. Here is a judgement value, judge, which is in the following inner loop. If this happens: a non-empty coordinate point has no data for the coordinate position of the odd function and the coordinate position of the corresponding dual function (as space characters), as long as this happens, the function must be non-odd and non-even, judge will be set to 0, The outer loop then terminates because of the first break statement. The end of the inner loop depends on the second and third break statements, and the line on which the second break statement is located determines whether this has occurred (k1 cannot equal 30 at this time).

Under the inner cycle, there is a special value to be judged separately, that is, line0, when k1=30. When K1 is not equal to 30, the second and third judgment statements mean that if a coordinate point data is the same as its corresponding coordinate point data for odd functions, that is, it meets the requirements of odd functions, then add a 1 to judgelist. Similarly, if it meets the requirements of even functions, add a 2. If it does not, it is the first judgment statement. It adds a zero to the judgelist and sets judge 0 to end the outer loop, then break s to end the inner loop, so the nested loop terminates directly.

In the case of k1=30, it is only necessary to compare whether the two horizontal coordinates symmetrical with respect to the origin are equal (both have data or none). If they do not conform, they are not odd or even functions, otherwise, they are not processed (because the coordinate data on the x-axis cannot distinguish the odd and even functions!)

Finally, outside the nested loop, the parity of the function is determined by the judgelist case. This is easier to understand, so don't talk about that much, just one thing. When judgelist is empty, the image of the function is all on the x-axis, and it satisfies both the definition of odd and even functions (e.g. function: y=0), which is a special case: odd and even functions

(5) The output of data analysis results is very simple! The maximum value can be directly operated on by min function and max function, parity can be output directly by parity, and the same is true for undefined independent variables.

(8) Circular operation of large circulation

[Lazy people must, and they don't need users to calculate once to run a program, and the big loop never stops.)

Source Code: (All lines have an extra indent under the big loop)

################################################### cycle operation ###################################################
    print('');end = input('press any key to continue...')

Did you find any problems? Yes! From the first time under the big loop, all the code has an extra indent!

Code Analysis:

(1) print('') is only for an empty line, for aesthetic purposes.

(2) This input function pauses the loop. If the user does not enter any value, the program will stay there all the time, but here you assign an unrelated string to an unrelated variable, no matter what you enter, or even an empty value (carriage return), and then you continue to return to the beginning of the original loop.

(3) Here we're going to recall the previous token: UNSTOP, remember the big loop that didn't stop, and instead of break ing it down, we used a special way to pause it, then continue, return to its starting position, and redraw the function image. This prevents the user from using the program many times and running the program many times. It will be done once and for all!

Additional instructions:

A comrade will ask: How does this program end? I just want to say, isn't it good to just close the running software or the running window?

3. Blogger has a message

(1) You are the three provinces of your day:

Seeing this, have you already complimented? Are you already collecting? Are you already concerned?

(2) Three provinces in our daily life:

How on earth can I get your approval? Can I let you collect it? Can I focus your attention?

Full Toy Source Download Link (to credit oh): Python: Draw Function Scatter Coordinate Map.py-Other Document Class Resources-CSDN Download

But you can also copy the code directly here.

Posted by xmatthawkx on Thu, 02 Dec 2021 09:25:50 -0800