我有以下代码:
d = sns.FacetGrid(data = df,
col = 'Company',
sharex = False,
sharey = False,
col_wrap = 4)
d.map(sns.distplot, 'Volume', kde = False, rug = True, fit = stats.norm)
d.set_xlabels('volume')
d.set_xticklabels(rotation = 45)
plt.savefig(myDataRepository + 'figure_02__' + str(time_stamp) + '.png')
ax.get_xaxis().set_major_formatter(
matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ',')))
最后两行尝试用逗号分隔 x 轴值。例如,“500,000”而不是“500000”。
我看到一条错误消息:
"global name ax is not defined"
我该如何修改ax.
这样我就可以用逗号分隔格式化 x 轴值?
提前致谢!
---编辑如下---
这是我发布的更新代码。它仍然失败,但这次出现错误消息@property
评估时
d.ax.get_xaxis().set_major_formatter(tkr.FuncFormatter(lambda x, p: format(int(x), ',')))
修改后的代码:
fig, ax = plt.subplots()
d = sns.FacetGrid(data = df,
col = 'Company',
sharex = False,
sharey = False,
col_wrap = 4)
d.map(sns.distplot, 'Volume', kde = False, rug = True, fit = stats.norm)
d.set_xlabels('volume')
d.set_xticklabels(rotation = 45)
plt.savefig(myDataRepository + 'figure_02__' + str(time_stamp) + '.png')
d.ax.get_xaxis().set_major_formatter(tkr.FuncFormatter(lambda x, p: format(int(x), ',')))
@cphlewis
建议我将 ax.get_axis() 放入 Facet Grid 中。但怎么办?
Putting ax.get_axis()
FacetGrid 内部似乎没有解决这个问题(假设我做得正确)。是不是均匀possible使用这个ax.get_axis()
与 Seaborn FacetGrid 一起使用吗?
错误信息:
971 return self.axes[0, 0]
972 else:
--> 973 raise AttributeError
974
975 @property
AttributeError: