我使用下面的脚本来使用包含x和y数据的两个列表来绘制集群人口
# calculate clusters using encore method
cluster = encore.cluster(u, select="all", superposition=False, method=encore.DBSCAN(eps=1))
# make list of population of each cluster;
cluster_sizes= [len(c) for c in cluster.clusters]
# make list of the cluster number;
cluster_numbers=[x+1 for x in range(0,len(cluster_sizes))]
# plot data
plt.bar(cluster_numbers, cluster_sizes)
plt.title('Cluster Populations')
plt.grid(True)
#plt.style.use('ggplot')
plt.savefig(f'clusters.png')
plt.close()问题是,有时在结果的条形图上,值沿X和Y的范围为0.5 (见所附图片作为示例)。我怎么能只绘制两个轴上的整数呢?在我的示例图中,X应该从0到20 (避免0.5行)和Y从0到18 (因此

避免这些未使用的0.5间隔)
发布于 2020-11-25 16:16:08
使用plt.xticks - https://matplotlib.org/3.1.1/api/_作为_gen/matplotlib.pyplot.xticks.html.
人们可以把xticks np.arange(len(cluster.clusters))作为一个论点
对于yticks,它的工作方式与传递给np.arange(int(max(cluster_sizes)))的-if相同,在y-axis上会有整数号。
https://codereview.stackexchange.com/questions/252660
复制相似问题