回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我试图用一些数据创建一个简单的条形图(这里是硬编码的,但我会在某个时候从文件中读入它)。到目前为止,我可以得到条形图,但我希望属性“Feature Name”出现在每个条下面。现在,我只知道1到16号。我能做什么使每个功能条下的每个功能?在</p>
<p>我的代码:</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
import mpld3
fig, ax = plt.subplots()
N = 17
feature_name = ('AccountLength','Intlact','Vmailact','Vmailnumber','day minutes','day calls','day charge','evening minutes','evening calls','evening charge','night minutes','night calls','night charge','intl minutes','intl calls','intl charge','cust calls')
importance = (0.0304,0.0835,0.0222,0.0301,0.1434,0.0315,0.1354,0.0677,0.0268,0.0669,0.0386,0.0286,0.0371,0.0417,0.0521,0.0434,0.1197)
ind = np.arange(N)
width = 0.20
rects = ax.bar(ind, importance, width, color = 'r')
ax.grid(color='white', linestyle='solid')
ax.set_title("Why are my customers churning?", size=20)
ax.set_ylabel('Importance in percentage')
ax.set_xlabel('Feature Name')
ax.set_xticklabels( (feature_name) )
labels = (feature_name)
tooltip = mpld3.plugins.PointLabelTooltip(rects, labels=labels)
mpld3.plugins.connect(fig, tooltip)
mpld3.show()
</code></pre>
<p>编辑:如果我用表演(),我可以看到ticklabels,但当我尝试在mpld3中执行相同的操作时,它不起作用。还想知道为什么工具提示没有出现。在</p>