01 matplotlib绘图初体验
matplotlib 可以繪制什么圖?
- 前言
- 一、折線圖
- 1.1 折線圖的介紹
- 1.2 代碼及運行結果
- 二、散點圖
- 2.1 散點圖的介紹
- 2.2 代碼及運行結果
- 三、餅圖
- 3.1 餅圖的介紹及使用要求
- 3.2 代碼及運行結果
- 四、條形圖
- 4.1 條形圖的介紹及使用情景
- 4.2 代碼及運行結果
- 五、直方圖
- 5.1 直方圖的介紹
- 5.2 代碼及運行結果
- 六、箱線圖
- 6.1 箱線圖的介紹
- 6.2 代碼及運行結果
- 七、參考資料
前言
本文僅初步體驗matplotlib繪圖,無須深究代碼。希望大家對matplotlib繪圖有初步的了解,認識各種圖形的應用情景,免用圖于不當之處,適得其反。同時對于疏漏之處,希望大佬們不吝賜教。
一、折線圖
1.1 折線圖的介紹
A line chart or line plot or line graph or curve chartis a type of chart which displays information as a series of data points called ‘markers’ connected by straight line segments.It is a basic type of chart common in many fields. It is similar to a scatter plot except that the measurement points are ordered(typically by their x-axis value) and joined with straight line segments. A line chart is often used to visualize a trend in data over intervals of time – a time series – thus the line is often drawn chronologically. In these cases they are known as run charts.1
1.2 代碼及運行結果
x = np.arange(10) y = np.sin(x) fig, ax = plt.subplots() ax.plot(x, y) plt.show()二、散點圖
2.1 散點圖的介紹
A scatter plot (also called a scatterplot, scatter graph, scatter chart, scattergram, or scatter diagram) is a type of plot or mathematical diagram using Cartesian coordinates to display values for typically two variables for a set of data. If the points are coded (color/shape/size), one additional variable can be displayed. The data are displayed as a collection of points, each having the value of one variable determining the position on the horizontal axis and the value of the other variable determining the position on the vertical axis.2
2.2 代碼及運行結果
x = np.arange(10) y = np.sin(x) fig, ax = plt.subplots() ax.scatter(x, y) plt.show()三、餅圖
3.1 餅圖的介紹及使用要求
A pie chart (or a circle chart) is a circular statistical graphic, which is divided into slices to illustrate numerical proportion. In a pie chart, the arc length of each slice (and consequently its central angle and area), is proportional to the quantity it represents. 3
- 每個數值代表一個類別
- 要繪制的數值沒有負值
- 要繪制的數值機會沒有零值
- 類別數目無限制
- 各類別分別代表整個餅圖的一部分
- 各個部分需要標注百分比4
3.2 代碼及運行結果
data = [0.3, 0.7] fig, ax = plt.subplots() ax.pie(data) plt.show()四、條形圖
4.1 條形圖的介紹及使用情景
A bar chart or bar graph is a chart or graph that presents categorical data with rectangular bars with heights or lengths proportional to the values that they represent. The bars can be plotted vertically or horizontally. A vertical bar chart is sometimes called a column chart.5
A bar graph shows comparisons among discrete categories. One axis of the chart shows the specific categories being compared, and the other axis represents a measured value. Some bar graphs present bars clustered in groups of more than one, showing the values of more than one measured variable.5
Bar charts have a discrete domain of categories, and are usually scaled so that all the data can fit on the chart. When there is no natural ordering of the categories being compared, bars on the chart may be arranged in any order. Bar charts arranged from highest to lowest incidence are called Pareto charts.5
Bar graphs/charts provide a visual presentation of categorical data. Categorical data is a grouping of data into discrete groups, such as months of the year, age group, shoe sizes, and animals. These categories are usually qualitative. In a column bar chart, the categories appear along the horizontal axis; the height of the bar corresponds to the value of each category.5
4.2 代碼及運行結果
x = np.arange(10) y = np.sin(x) fig, ax = plt.subplots() ax.bar(x, y) plt.show()五、直方圖
5.1 直方圖的介紹
直方圖(Histogram),又稱質量分布圖,是一種統計報告圖,由一系列高度不等的縱向條紋或線段表示數據分布的情況。 一般用橫軸表示數據類型,縱軸表示分布情況。
直方圖是數值數據分布的精確圖形表示。 這是一個連續變量(定量變量)的概率分布的估計,并且被卡爾·皮爾遜(Karl Pearson)首先引入。它是一種條形圖。 為了構建直方圖,第一步是將值的范圍分段,即將整個值的范圍分成一系列間隔,然后計算每個間隔中有多少值。 這些值通常被指定為連續的,不重疊的變量間隔。 間隔必須相鄰,并且通常是(但不是必須的)相等的大小。
直方圖也可以被歸一化以顯示“相對”頻率。 然后,它顯示了屬于幾個類別中的每個案例的比例,其高度等于1。6
5.2 代碼及運行結果
x = [1, 1, 2, 3, 3, 3, 4] fig, ax = plt.subplots() ax.hist(x) plt.show()六、箱線圖
6.1 箱線圖的介紹
箱線圖(Boxplot)也稱箱須圖(Box-whisker Plot),是利用數據中的五個統計量:最小值、第一四分位數、中位數、第三四分位數與最大值來描述數據的一種方法,它也可以粗略地看出數據是否具有有對稱性,分布的分散程度等信息,特別可以用于對幾個樣本的比較。7
6.2 代碼及運行結果
x = [1, 1, 2, 3, 3, 3, 4, 4] fig, ax = plt.subplots() ax.boxplot(x) plt.show()七、參考資料
https://encyclopedia.thefreedictionary.com/line+chart ??
https://encyclopedia.thefreedictionary.com/scatter+plot ??
https://encyclopedia.thefreedictionary.com/pie+chart ??
https://baike.baidu.com/item/%E9%A5%BC%E5%9B%BE/10816566 ??
https://encyclopedia.thefreedictionary.com/bar+chart ?? ?? ?? ??
https://baike.baidu.com/item/%E7%9B%B4%E6%96%B9%E5%9B%BE/1103834 ??
https://wiki.mbalib.com/wiki/%E7%AE%B1%E7%BA%BF%E5%9B%BE ??
總結
以上是生活随笔為你收集整理的01 matplotlib绘图初体验的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SAP外协加工模式中原料直发加工商时无法
- 下一篇: html 图片取消纵横比,html –