使用 Matplotlib 显示条形图
在本教程中,我们将使用 matplotlib 库绘制条形图。借助 matplotlib 库解决与 matplotlib 相关的问题时,最重要的步骤是导入 matplotlib 库。语法为:
import matplotlib.pyplot as plt
Pyplot 是一个命令风格的函数集合,它使 Matplotlib 能够像 MATLAB 一样工作
算法
Step 1: Define a list of values. Step 2: Use the bar() function in the matplotlib.pyplot library and define different parameters like height, width, etc. Step 3: Label the axes using xlabel() and ylabel(). Step 3: Plot the graph using show().
示例代码
import matplotlib.pyplot as plt
data_x = ['Mumbai', 'Delhi', 'Ahmedabad', 'Banglore']
data_y = [40, 35, 29, 32]
plt.xlabel("CITY")
plt.ylabel("POPULATION")
plt.title("BAR PLOT")
plt.bar(data_x, data_y, color='red')
plt.show()输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP