We also used the title function to define the title of the plot.Next, we used the xlabel and the ylabel functions to define the labels. After the plot, we also used the text function to add the annotation to the points. Using the color attribute, we defined the color of the plot, and using the marker we defined the marker style of the plot. We used the scatter function to plot the figure.Under each iteration, we unpacked the value of x and y using the indexing. Under this function, we iterated through the iterable ‘words’.This is a void function, and it takes three arguments, namely values, dictionaries, and words. Next, we created a user-defined function named scatter_plot.We imported random and the numpy library in the code.'co-ordinate3', 'co-ordinate4', 'co-ordinate5'] Values = np.array(,, ,, ])ĭictionary = # Defining the coordinates in the form of pairs # Creating the figure object and defining the figure size. Plt.scatter(x, y, marker='+', color='green') # Import all the necessary libraries and packages in the code.ĭef scatter_label(values, dictionary, words): We can annotate the plots using the combination of previously discussed functions with a dictionary. Dictionaries allow us to have the search operation in O(1) space complexity hence, they are very efficient in the search algorithms. Many times we often get the data in the form of dictionaries. We called the scatter_plot function next to plot the graph. We used the zip function to make pairs from the two variables. Under the function, we created all the data points using the numpy library. After the scatter_plot function, we created the main function. ![]() We also defined the title of the function using the title function of matplotlib. Next, we defined the labels along the axes using the xlabel and the ylabel function.The first parameter is the text we need to display, and the second is the coordinate we need to plot. We passed two parameters to the function. After that, we iterated through the variable n and used the annotate function to make the annotation.Using the color function, we defined the color of the plot. We plotted the graph using the scatter function. ![]() Next, we used the axes function of Matplotlib to create the axes object.Under this function, we first defined the size of the figure using the figsize function. This is a void function again, and it takes three parameters, namely x, y, and z. Next, we created a user-defined function called scatter_plot.You are free to import them anywhere in the program. Note that it is not required to import the libraries at the top. We imported all the libraries and codes in our program at the top.# Iterating through the n variable and creating the annotation Finally, we called the main function using the following lines of codes: if _name_ = “ main“: main()Ĭheck This: I have wrote a full guide on Matplotlib Scatter Plot if you want to know more about scatter plot in python matplotlib library (What it is and how to plot a scatter plot using different functions and techniques).We called the scatter_plot function to plot the graph. Then we converted the data type of the zip into a list using the list function. We made pair from y and z using the zip function. We used the arange function of numpy to create the data points. Under this function, we defined the data points for the plot. We created the main function, which is the driving code of our program.Next, we displayed the graph using the show function. We also defined the title of the plot using the title function. Next, we defined the labels along the x and y axes using the xlabel and ylabel functions.And the third argument is the coordinate in which we should place the text. Second is the coordinates of the plot that we need to plot. First is the text that needs to be displayed as the annotation. Under each annotated function, we passed three parameters. ![]() ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |