Matplotlib
Matplotlib provides a wide range of plot types to visualize different types of data. Here are some of the commonly used plot types available in Matplotlib:
Line Plot
A line plot is a type of plot that displays the relationship between two continuous variables. It uses a series of data points connected by straight lines to show the trend or progression of the variables over a specified range or sequence. Line plots are commonly used to visualize time series data or to represent the change of a variable over different conditions or categories.
import matplotlib.pyplot as pyplot pyplot.plot([1,2,3,5,6], [1, 2, 3, 4, 6]) pyplot.axis([0, 7, 0, 10]) pyplot.show()
Scatter Plot
A scatter plot is a type of plot that shows the relationship between two continuous variables. It represents each data point as a point on the plot, with the x-axis representing one variable and the y-axis representing the other. Scatter plots are useful for identifying patterns, trends, or correlations between variables, and they can reveal clusters or outliers in the data.
import matplotlib.pyplot as pyplot x1 = [1, 2.5,3,4.5,5,6.5,7] y1 = [1,2, 3, 2, 1, 3, 4] x2=[8, 8.5, 9, 9.5, 10, 10.5, 11] y2=[3,3.5, 3.7, 4,4.5, 5, 5.2] pyplot.scatter(x1, y1, label = 'high bp low heartrate', color='c') pyplot.scatter(x2,y2,label='low bp high heartrate',color='g') pyplot.title('Smart Band Data Report') pyplot.xlabel('x') pyplot.ylabel('y') pyplot.legend() pyplot.show()
Bar Plot
A bar plot is a type of plot used to compare categorical or discrete data by representing the values of different categories as rectangular bars. The height or length of each bar corresponds to the magnitude or frequency of the data. Bar plots are effective in visualizing the distribution, comparison, or ranking of categorical data and are often used to display data grouped into different categories.
import matplotlib.pyplot as pyplot pyplot.bar([0.25,2.25,3.25,5.25,7.25],[300,400,200,600,700], label="Carpenter",color='b',width=0.5) pyplot.bar([0.75,1.75,2.75,3.75,4.75],[50,30,20,50,60], label="Plumber", color='g',width=.5) pyplot.legend() pyplot.xlabel('Days') pyplot.ylabel('Wage') pyplot.title('Details') pyplot.show()
Histogram
A histogram plot represents the distribution of a continuous variable by dividing the data into bins or intervals along the x-axis and displaying the frequency or density of data points within each bin as bars on the y-axis. Histogram plots are useful for understanding the shape, central tendency, and spread of the data, and they provide insights into the distribution of values and any potential outliers or patterns.
import matplotlib.pyplot as pyplot pop = [22,55,62,45,21,22,34,42,42,4,2,8] bins = [1,10,20,30,40,50] pyplot.hist(pop, bins, rwidth=0.6) pyplot.xlabel('age groups') pyplot.ylabel('Number of people') pyplot.title('Histogram') pyplot.show()
Pie Chart
A pie plot, also known as a pie chart, is a circular plot that displays the proportion or percentage of different categories or components in a dataset. Each category is represented by a slice of the pie, and the size of each slice corresponds to the relative frequency or proportion of the data. Pie plots are commonly used to show the composition or distribution of categorical data.
import matplotlib.pyplot as pyplot slice = [12, 25, 50, 36, 19] activities = ['NLP','Neural Network', 'Data analytics', 'Quantum Computing', 'Machine Learning'] cols = ['r','b','c','g', 'orange'] pyplot.pie(slice, labels =activities, colors = cols, startangle = 90, shadow = True, explode =(0,0.1,0,0,0), autopct ='%1.1f%%') pyplot.title('Training Subjects') pyplot.show()
Area plot
An area plot, also called a filled area plot or stacked area plot, visualizes the quantitative contribution of multiple variables or categories over a continuous or discrete range. It displays the areas beneath a series of lines or curves, with each area representing the cumulative value or proportion of a variable. The areas are stacked on top of each other, allowing for the comparison of contributions and the overall distribution of the data.
import matplotlib.pyplot as pyplot days = [1,2,3,4,5] age =[63, 81, 52, 22, 37] weight =[17, 28, 72, 52, 32] pyplot.plot([],[], color='c', label = 'Weather Predicted', linewidth=5) pyplot.plot([],[],color = 'g', label='Weather Change happened', linewidth=5) pyplot.stackplot(days, age, weight, colors = ['c', 'g']) pyplot.xlabel('Fluctuation with time') pyplot.ylabel('Days') pyplot.title('Weather report using Area Plot') pyplot.legend() pyplot.show()
Комментарии
Отправить комментарий