plot function python usage

 

Plot is a basic data type in Python, which can be used to calculate the coordinates and area of ​​points, and can also be used to make pie charts. The plot function has two parameters, namely: plot (x, y): used to calculate the area of ​​the data. In Python, the plot function has two forms: The first form is: Among them, plot () is an ordinary list function used to calculate the area of ​​a series of points. However, if we want to calculate the area of ​​all the pie charts, rather than the area of ​​a single point, we need to use the plot() function. In order to calculate the distance (i.e. area) between two or more data points, the plot() function can be used. For example, if we want to calculate the distance between two points, we can use the plot() function to calculate the distance between them. Note: In Python, the plot() function doesn't return a value, which means it returns a value when you use it. In other languages, you might return a string or a list.

  • 1. Definition

    NOTE: When you use plot(), you're returning a list that will center a point and draw a pie chart with the coordinates of that point as a radius. where x is the number of points and y is the coordinates of the points. If we want to connect multiple points into a line instead of a single line, we can use the plot(x) function to draw a pie chart. Please note: In Python, the plot(x) function can be used to calculate the distance between multiple points.

  • 2. Grammatical format

    In Python, the plot() function can return two values: a list, and a value. Each value in the list appears in some format, such as "=", ">". Here is some sample code: Note: If you want to use list functions to calculate the distance between two points, you need to change the function to = or <. Value: When you use the plot() function, you return a value. For example, in the example below, we changed the function to = and return a value. Both lists and values ​​have a fixed format: A list is a data type used to preserve the order or position of points. In Python, lists can be used to store points, coordinates, and lengths. Note: Lists can also be used to store the length of data. In the example below, we change a list to a string expression: Note: Lists are one of the most common data types in Python. Other data types include integers (int, double, float), floating point (one of the most common data types in python), and characters (such as byte, short, etc.). These data types are also known as "arrays" or "objects". Note: When you use the plot() function to calculate the distance between two points, you need to use an array to store these array elements.

  • 3. Function

    We can use the following code to demonstrate this functionality: Here, we want to calculate the distance (that is, the area) between two points. Note that in the code above, the plot(x,y) function is a list function. But in this code, it's a function that returns the distance between two points. Please note: When calculating area using a list function, it returns not the area of ​​a single point (i.e. the area), but the sum of the distances from one point to other points. In plot, we can also use it to make pie charts. For example, the following piece of code shows the calculation process of all areas in a pie chart: If we want to calculate all the areas in a pie chart (that is, the sum of the distances between each point and other points), please use the following code :

  • 4. Usage scenarios

    1. Calculate the coordinates of a point The plot() function provides a simple function that can calculate the coordinates of a set of points. Suppose we have a dataset named "clear_data_x_y_gt" where xi, yi and gt are all points. The plot() function will calculate the coordinates of a point and return its position. 2. Calculate the area of ​​an area We can use the plot() function to calculate the area of ​​these points and plot them in a pie chart. For example: 3. To calculate the distance between two points In the plot() function, we will use the specified numerical value as an argument. For example: Note: In Python, when we want to calculate the distance between two points, the plot() function is not available. 4. Draw a pie chart The plot () function can draw a pie chart, which shows the distance between these points.

  • 5. Sample code

    In this article, we will use a basic function in Python to create a pie chart which calculates the area of ​​the data using the plot() function. This function takes two parameters, one of which is the variable plot() and the other parameter is the type of the variable. Below is a simple example that can be used to better understand how to use this function. For example, we need to calculate the distance between the three points "a, b, c". Here is a simple sample code that outputs the distance between three points: In the code, we input the following: For the first parameter x, we want to calculate the row it is in the table; for The second parameter y, we want to calculate the column it is in the table.

  • The following is the commonly used plot function code in Python:
    ```python
    import matplotlib.pyplot as plt
    # Draw a line graph
    plt.plot(x, y, label='line')
    plt.xlabel('x')
    plt.ylabel( 'y')
    plt.title('title')
    plt.legend()
    plt.show()
    # Draw a scatter plot
    plt.scatter(x, y, label='points')
    plt.xlabel('x')
    plt .ylabel('y')
    plt.title('title')
    plt.legend()
    plt.show()
    # Draw a histogram
    plt.bar(x, y, label='bars')
    plt.xlabel('x' )
    plt.ylabel('y')
    plt.title('title')
    plt.legend()
    plt.show()
    # Draw a histogram
    plt.hist(x, bins=10, label='histogram'
    plt.xlabel('x')
    plt.ylabel('frequency')
    plt.title('title')
    plt.legend()
    plt.show()
    # Draw a pie chart
    plt.pie(x, labels=labels, autopct='%1.1f%%')
    plt.title('title')
    plt.show()
    ```
    Among them, x and y are the horizontal and vertical coordinates of the data, labels are the labels of the pie chart, and bins are the number of groups in the histogram. Other parameters can be adjusted as needed.

Guess you like

Origin blog.csdn.net/qq_42751978/article/details/129968161