python - 在多轴图中旋转 xtick 标签
问题描述
我想在这个多轴图中旋转 xtick 标签(我用于单轴图的代码不起作用)。
编码
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import host_subplot
from mpl_toolkits import axisartist
# Create the data
data = {
'Date': pd.date_range('2021-01-1', '2021-01-30'),
'Close': np.linspace(100, 200, num=30) + np.random.normal(scale=10, size=30),
'Volume': np.random.randint(500, 2000, size=30)
}
df = pd.DataFrame(data)
df = df.set_index(df.Date)
# Create the axis
plt.figure(figsize=(10,5))
host = host_subplot(111, axes_class=axisartist.Axes)
ax1 = host.twinx()
ax1.axis["right"].toggle(all=True)
# Plot the closing prices
line, = host.plot(df.index, df.Close, label="Close")
host.set_ylabel("Close")
host.yaxis.label.set_color(line.get_color())
# Plot the volumes
bar = ax1.bar(df.index, df.Volume, alpha=0.2, color='red', label="Volume")
ax1.set_ylabel('Volume')
ax1.yaxis.label.set_color('red')
host.legend()
plt.show()
该代码基于此 matplotlib 示例:
https ://matplotlib.org/stable/gallery/axisartist/demo_parasite_axes2.html#sphx-glr-gallery-axisartist-demo-parasite-axes2-py
单轴图的正常解决方案不起作用,例如。在 python matplotlib 中旋转轴文本
解决方案
推荐阅读
- magento - Magento 2 REST API。列出具有父/子关系的产品
- tcp - erlang VM 占用大约 600 个 os/windows 机器线程
- javascript - 简单赋值帮助:调用函数向其传递参数并获取其返回值
- javascript - 异步方法返回未定义
- python - Extracting a numerical value from .csv files
- wordpress - 将自定义属性添加到联系表单本身(wordpress 插件)
- javascript - How to assign the query responses to the global.arrays, not the value inside the array of global.arrays?
- javascript - express js 无法获取/注册
- java - 删除单个链表上的节点的最有效方法?
- python - 从 numpy 二维数组中一次删除多个元素