python-3.x - Overlay median values line graph on a barchart of counts by category in python
问题描述
The following code gives me bar charts that give a count per category. I would like to overlay the median value of a numeric feature per unique category.
What would I need to add to the following code?
def plot_bars(xy_merge, cols):
for col in cols:
fig = plt.figure(figsize=(6,6)) # define plot area
ax = fig.gca() # define axis
counts = xy_merge[col].value_counts() # find the counts for each unique category
counts.plot.bar(ax = ax, color = 'blue') # Use the plot.bar method on the counts data frame
ax.set_title('Counties and median log rental per categorical variable: ' + col) # Give the plot a main title
ax.set_xlabel(col) # Set text for the x axis
ax.set_ylabel('Count')# Set text for y axis
plt.show()
plot_cols = ['state', 'rucc', 'urban_influence']
plot_bars(xy_merge, plot_cols)
解决方案
推荐阅读
- python-3.x - 如何使用可微张量流方法将张量分配给另一个张量的切片
- python - 发布数据有表单输入,但 Django modelform 没有保存它
- php - PHP如何将缺少的序列号查找到字母数字系列中
- python - 如何根据多列中的字符串匹配选择 Pandas 数据框中的行
- javascript - 如何将响应式 DIV 大小传递给 PHP?
- python - 如何从已经确定的峰/谷指数组中获得极值?[Python]
- mysql - 需要逻辑来为mysql中同一表中另一列的最小值找到一列的值
- android - 想要自定义带有提示的 EditText 属性
- excel - VBA 查找区分大小写的 DUPLICATE 行而不是单元格并删除
- .htaccess - .htaccess 检测桌面或移动设备并自动重定向