matplotlib.pyplot.bar()
时间: 2023-10-25 16:01:28 浏览: 48
函数matplotlib.pyplot.bar()是用来绘制垂直条形图的。它的函数签名为matplotlib.pyplot.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)。在这个函数中,x表示条形图的位置,height表示每个条形图的高度,width表示条形图的宽度,默认为0.8。bottom表示条形图的基线位置,align表示条形图的对齐方式(默认为'center')。data参数可以传入一个DataFrame或一个类似数组的数据对象。其他的参数可以用来设置条形图的颜色、边框颜色、线宽等。如果你想绘制简单的水平条形图,你可以使用面向对象编程的方式,例如:import matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(5,5))
ax=plt.axes()
x=np.arange(0,6)
y=np.random.random(6)
ax.barh(x,y)
plt.show()<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [matplotlib之pyplot模块之柱状图(bar():基础参数、外观参数)](https://blog.csdn.net/mighty13/article/details/113869911)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* [matplotlib.pyplot.bar()与barh()绘制条形图](https://blog.csdn.net/Yangyuqing_/article/details/124180245)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]