python - 在条形图之间创建空间
问题描述
我正在研究以前在此论坛上发布的示例之一。我想在每个图之间放置空格,因为索引有重叠,我几乎看不懂它。这是代码:
import numpy as np
import matplotlib.pyplot as plt
# Data
states = ["AK", "TX", "CA", "MT", "NM", "AZ", "NV", "CO", "OR", "WY", "MI",
"MN", "UT", "ID", "KS", "NE", "SD", "WA", "ND", "OK",
"AK1", "1TX", "C1A", "1MT", "N1M", "A1Z", "N1V", "C1O", "O1R", "W1Y", "1MI",
"MN1", "UT1", "ID1", "KS1", "NE1", "S1D", "WA1", "ND1", "O1K", ]
staff = np.array([20, 30, 40, 10, 15, 35, 18, 25, 22, 7, 12, 22, 3, 4, 5, 8,
14, 28, 24, 32, 20, 30, 40, 10, 15, 35, 18, 25, 22, 7, 12, 22, 3, 4, 5, 8,
14, 28, 24, 32])
sales = staff * (20 + 10 * np.random.random(staff.size))
# Sort by number of sales staff
idx = staff.argsort()
states, staff, sales = [np.take(x, idx) for x in [states, staff, sales]]
y = np.arange(sales.size)
fig, axes = plt.subplots(ncols=2, sharey=True)
axes[0].barh(y, staff, align='center', color='gray', zorder=10)
axes[0].set(title='Number of sales staff')
axes[1].barh(y, sales, align='center', color='gray', zorder=10)
axes[1].set(title='Sales (x $1000)')
axes[0].invert_xaxis()
axes[0].set(yticks=y, yticklabels=states)
axes[0].yaxis.tick_right()
for ax in axes.flat:
ax.margins(0.03)
ax.grid(True)
fig.tight_layout()
fig.subplots_adjust(wspace=0.19)
plt.show()
并输出:
谁能帮我解决这个问题?
解决方案
推荐阅读
- java - 在 JavaFX 中特定行数后截断文本
- r - 聚合来自具有相同结构的多个 excel 文件的数据
- azure - 使用 Power BI 在 Azure HDInsight 中可视化 Hbase
- javascript - 从总值中添加或减去函数
- javascript - 在 Vue 的挂载钩子中未定义 javascript 对象的函数
- docker - 在非特权的基于 Ubuntu 的 Docker 容器中使用 gcsfuse 拒绝权限
- java - 从 https 登录后自动重定向到 http
- java - 如何使用管道 IO 流
- javascript - 有没有办法自动更改特定的文本颜色,使其适合背景颜色?
- javascript - 为什么 nuxt.js 在 SSR 中调用 beforeCreate, created 钩子?