MatPlotLib散点重绘扩展x轴

时间:2018-12-19 05:33:37

标签: python matplotlib

我是pythonmatlotlib的新手。我试图用matplotlib绘制散点图,并按行业分组。但是,当我遍历各个行业并将其添加到图中时,输出将重绘并将轴延伸到重新使用和缩放现有轴的内部。结果使所有刻度线不可读,并将每个行业并排放置,而不是放在同一轴上:

temp = data[data.Year == 2017]
data = pd.read_csv(path, encoding='latin1')
data['Company'] = pd.Categorical(data['Company'])
data['Industry'] = pd.Categorical(data['Industry'])

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)

for ind in temp.Industy.unique():
   temp2 = temp[temp.Company == ind]

   revGrowth = temp2["RevGrowth"]
   EBITMargin = temp2['EBITMargin']
   scatter_plot = ax.scatter(revGrowth, EBITMargin, s=40, alpha=0.8,label=ind)

plt.legend(loc='upper right', bbox_to_anchor=(1.3, 1.05), fontsize=8, frameon=False)
plt.xticks(rotation=90)
plt.xlabel("Revenue Growth YoY (%)")
plt.ylabel("Return on Assets (%)")
plt.title("Industry Growth vs Profitability 2017\n")
plt.tight_layout()
plt.savefig("xx")

image 1

我该如何解决?

0 个答案:

没有答案