我正在通过matplotlib创建面积图,并且未显示x轴标签(索引)。这是我的代码:
import pandas
import matplotlib.pyplot as plot
def graphing():
data2 = [(12.20, 14.50, 15.60, 24.80),
(11.30, 8.70, 23.20, 10.0),
(6.40, 10.70, 22.60, 11.60),
(15.0, 16.0, 23.40, 10.8)]
columns = ["Expense Management", "Guidance", "Interest Rate and Deposit Costs", "Loan Growth"]
index = ["2019Q3", "2019Q2", "2019Q1", "2018Q4"]
df2 = pandas.DataFrame(data=data2, index=index, columns=columns)
graph2 = df2.plot.area(stacked='True')
graph2.axes.get_yaxis().set_visible(False)
plot.show(block=True)
graphing()
我添加了诸如“ graph2.axes.get_xaxis()。set_visible(True)”之类的行,它不会显示我的索引标签。对我该怎么办有什么想法?
答案 0 :(得分:0)
您必须这样做:
graph2.axes.get_xaxis().set_visible(True)
评论后编辑: 抱歉,我无法重新创建您的问题。对我来说,以下代码可以正常工作:
import pandas
import matplotlib.pyplot as plot
def graphing():
data2 = [(12.20, 14.50, 15.60, 24.80),
(11.30, 8.70, 23.20, 10.0),
(6.40, 10.70, 22.60, 11.60),
(15.0, 16.0, 23.40, 10.8)]
columns = ["Expense Management", "Guidance", "Interest Rate and Deposit Costs", "Loan Growth"]
index = ["2019Q3", "2019Q2", "2019Q1", "2018Q4"]
df2 = pandas.DataFrame(data=data2, index=index, columns=columns)
graph2 = df2.plot.area(stacked='True')
graph2.axes.get_yaxis().set_visible(False)
graph2.axes.get_xaxis().set_visible(True)
plot.show(block=True)
graphing()