并列条形图python
时间: 2023-10-17 15:34:02 浏览: 101
要绘制并列条形图,可以使用Python中的Matplotlib库。下面是一个示例代码来绘制并列条形图:
```python
import matplotlib.pyplot as plt
import numpy as np
waters = ('高新', '历城', '市中', '历下', '槐荫')
high = [8, 5, 3, 2, 4]
low = [40, 25, 25, 25, 7]
bar_width = 0.3
index_male = np.arange(len(waters))
index_female = index_male + bar_width
plt.bar(index_male, height=high, width=bar_width, color='mediumaquamarine', label='最高')
plt.bar(index_female, height=low, width=bar_width, color='salmon', label='最低')
plt.legend()
plt.xticks(index_male + bar_width/2, waters)
plt.ylabel('薪资单位:K')
plt.title('各个区最高薪资和最低薪资统计表')
plt.show()
```
这段代码使用了Matplotlib库来绘制并列条形图。首先定义了需要显示的数据和标签,然后使用`plt.bar`函数分别绘制最高薪资和最低薪资的条形图。设置`bar_width`参数用于调整条形的宽度,`index_male`和`index_female`分别是最高薪资和最低薪资的横坐标位置。最后使用`plt.legend`添加图例,`plt.xticks`设置横坐标刻度,`plt.ylabel`设置纵坐标标题,`plt.title`设置图形标题,最后使用`plt.show`显示图形。
这样就可以绘制出一个并列条形图,其中比较了各个区最高薪资和最低薪资的数据。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [python画并列条形图](https://blog.csdn.net/m0_62004321/article/details/125262000)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [python使用Plotly绘图工具绘制水平条形图](https://download.csdn.net/download/weixin_38739101/13783164)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [python实现绘制多组并列条形图](https://blog.csdn.net/sinat_41858359/article/details/124794252)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文