python - matplotlib的旋转轴注释文本:python
问题描述
我正在尝试注释我的所有数据点,但是注释时的文本彼此重叠,
fig = plt.figure(figsize=(70,2))
fig.autofmt_xdate()
plt.style.use('ggplot')
axess= plt.subplot(1,1,1)
axess.plot_date(idx2,stock2,'--')
axess.set_title("Doc_ID:7377")
axess.set_ylabel('1 - Online, 0 - Offline')
for i,txt in enumerate(date_match_df['service_name_'].tolist()):
print(txt)
axess.annotate(txt,(mdates.date2num(idx2[i]),stock2[i]),)
axess.yaxis.grid(True)
axess.xaxis.grid(True)
axess.xaxis.set_major_locator(dates.MonthLocator())
axess.xaxis.set_major_formatter(dates.DateFormatter('\n\n%b-%Y'))
axess.xaxis.set_minor_locator(dates.DayLocator())
axess.xaxis.set_minor_formatter(dates.DateFormatter('\n%d-%a'))
plt.tight_layout()
fig.savefig('happynewyear.svg')
如何旋转文本?
解决方案
-method 的其他参数.annotate()
被传递给Text,因此您可以执行以下操作:
for i,txt in enumerate(date_match_df['service_name_'].tolist()):
print(txt)
axess.annotate(txt,(mdates.date2num(idx2[i]),stock2[i]), ha='left', rotation=60)
您的代码的更改ha='left', rotation=60
最终是添加的。
推荐阅读
- function - 将 char** 映射到列表
使用 SWIG - python - 使用 boto3 附加的 EBS 卷没有 NVMe 块设备
- javascript - 从退出应用程序后离开的屏幕开始 -RN
- python - 如何在 django 测试中设置 ldap_user?
- python - Python Tensorflow“X”值无穷无尽
- c++ - make_shared 是否忽略显式说明符?
- networking - 是否可以设置 Windows NIC 设备 InterfaceIndex 属性?
- azure-devops - 库和环境上的新安全层
- aws-lambda - 无法在 DLQ 中写入消息
- ruby-on-rails - Rails 按两个关联列的总和排序