AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Triangle scatter plot matplotlib4/8/2023 ![]() MarkerĮxample of scatter plot for three different groups import matplotlib.pyplot as plt Line 9 and Line 10: Mentions the Chart Title with font size and scatter plot is shown.ĭifferent values for markers and their representation is shown below. Line 7 and Line 8: x label and y label with desired font size is created. Line 6: scatter function which takes takes x axis (weight1) as first argument, y axis (height1) as second argument, colour is chosen as blue in third argument and marker=’o’ denotes the type of plot, Which is dot in our case. Line 3 and Line 4: Inputs the arrays to the variables named weight1 and height1. Line 1: Imports the pyplot function of matplotlib library in the name of plt. Plt.title('scatter plot - height vs weight',fontsize=20) Plt.scatter(weight1,height1,c='b',marker='o') This example we will create scatter plot for weight vs height import matplotlib.pyplot as plt This python Scatter plot tutorial also includes the steps to create scatter plot by groups in which scatter plot is created for different groups. ![]() We also setted the x-coordinates and y-coordinates limit.In this Tutorial we will learn how to create Scatter plot in python with matplotlib. Then we created a numpy array and stored it in a variable named as “pts”, then we passed this numpy array in Polygon module. Here, we first imported two modules named as matplotlib and numpy, and then we imported polygon from “ matplotlib.patches“. Triangle shape in matplotlib – Python import numpy as np The “fc” attribute is used to denote the face color of the circle and the “ec” attribute denotes the edge color of the circle. Here, we created another object named as “ plt.Circle()” which takes mainly 2 arguments, first one indicates the position of the center of the circle, and the next arguments indicate the radius of the circle. Circle shape in matplotlib – Python import matplotlib.pyplot as pltĬircle = plt.Circle((0,0),1.5, fc='blue',ec="red") Here the only thing we changed is that we took the height and width data same, which then converted into a square from a rectangle. Square shape in matplotlib – Python import matplotlib.pyplot as plt If we take the height and width of the rectangle same, then it will get converted into a square. ![]() The “fc” attribute is used to denote the face color of the rectangle and the “ec” attribute denotes the edge color of the rectangle. Here, we created another object named as “ plt.rectangle()” which takes mainly 3 arguments, first one indicates the position of left-bottom corner of rectangle, and the next two arguments indicates the width and height of the rectangle. ![]() Rectangle shape in matplotlib – Python import matplotlib.pyplot as plt Now, we move to the next shape named as Rectangle. Then we used the concept of gca which return the current axis instances on the current figure. And then we created another object for line named as “ plt.Line2D()“(A line is a Line2D instance), this object takes 3 arguments, first two are tuples which indicating the position of both the ends of the line and the third arguments indicates the width of the line. Then we created an object named “ plt.axes()“. Here, we first imported the matplotlib module by writing “ import matplotlib.pyplot as plt“. Let’s start with Line:- Draw line shape in matplotlib – Python import matplotlib.pyplot as plt Here, we are going to draw 5 basic shapes. In this article during drawing different types of shapes, we use the concept of “ plt.gca()” which returns the current axes instances on the current figure. For this, we need some basic concepts of two popular modules in the field of plotting figure i.e. In this article, we are going to learn how to draw different types of basic shapes like Lines, Rectangle, Square, Circle, Triangle in matplotlib using Python.
0 Comments
Read More
Leave a Reply. |