繁体   English   中英

如何调整x轴宽度以适合和显示图中每个单词的字符串?

[英]How to adjust the x-axis width to fit and display each string of the words in the plot?

我试图将宽度设置为自动调整以适应x轴中的每个单词串。 这些词是“舰队”,“服务”,“信息技术”等等(总共约10个)

x = df.Category.astype(str)
y = df.Amount
plt.scatter(x,np.e**y,label ="$ Amount", color = "k", marker = "*", s = 3)

在此输入图像描述

请参阅x轴上的红色框。 需要清楚地传播这些词语。

我的建议是(如上所述)简单地交换x和y以在y轴上具有可读的类别名称:

在此输入图像描述


# Code to reproduce image above:

# import numpy as np
# import pandas as pd
# import matplotlib.pyplot as plt

# np.random.seed(42)
# cats = ['Facility', 'Fleet', 'Services', 'Information Technology', 'Facility2', 'Fleet2', 'Services2', 'Information Technology2']
# df = pd.DataFrame({'Category': np.random.choice(cats, 100000), 'Amount': np.random.random(100000)*750})
# x = df.Category.astype(str)
# y = df.Amount
plt.scatter(np.e**y, x, label ="$ Amount", color = "k", marker = "*", s = 3)
# plt.tight_layout()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM