问题描述
我有一个包含日期时间数据的数据框,其列说明了各个假期有多少天。我想创建该数据的直方图,然后尝试了以下代码:
holiday_features = [name for name in df.columns if 'DAYS FROM' in name]
for feature in holiday_features:
plt.hist(df[feature],bins=12)
plt.title(feature)
plt.xticks(rotation=60)
plt.show()
创建该循环时,出现如下所示的直方图:
看来,勾号代表了每个单独的功能,而不仅仅是垃圾箱。将直方图放大到淫秽比例即可确认:
我只对bin标记感兴趣,而不对功能标记感兴趣。如何删除那些刻度线以使整洁的直方图?
解决方法
我的建议是使用subplots,并在Axes类上操作xticks。
例如,对于单个图:
public class User
{
public int UserId { get; set; }
public string Username { get; set; }
[InverseProperty("Creator")]
public List<Compliment> SentCompliments { get; } = new List<Compliment>();
[InverseProperty("Destination")]
public List<Compliment> ReceivedCompliments { get; } = new List<Compliment>();
}
上面的代码产生的图具有以下美感:
另外,考虑到在您的情况下,您正在绘制许多要素,则可以使用subplots函数生成网格图,如下所示:
_,axis = plt.subplots(1,1) # create an Axes class for a single plot
axis.hist(data,bins=12)
axis.set_xticklabels(axis.get_xticks(),rotation=60)
plt.show()