简体   繁体   中英

How to change the ticks on x-axis?

I want change the x-axis ticks. I want: 0 10 20 30 40 50 ...

    with pydicom.dcmread(directory) as dataset:
        all_population_ages.append(dataset.PatientAge)

plt.hist(all_population_ages,  histtype='bar', rwidth=0.8)
plt.xticks(np.arange(0, 100, step=10))
plt.show()

Output:

历史图像

I tried this solution: Changing the "tick frequency" on x or y axis in matplotlib?

plt.xticks(np.arange(min(x), max(x)+1, 1.0))

plt.xticks(np.arange(min(all_population_ages), max(all_population_ages) + 1, 10.0))

But receive an error:

plt.xticks(np.arange(min(all_population_ages), max(all_population_ages) + 1, 10.0))

TypeError: must be str, not int

Thanks in advance for any assistance.

Done.

results = list(map(int, all_population_ages))
    bins = np.arange(0, 100, 5)  # fixed bin size
    plt.rcParams.update({'font.size': 8})
    plt.hist(results, bins=bins, alpha=0.5, rwidth=0.8)
    plt.xticks(np.arange(0, 100, 5))

I changed list of string to list of int. I changed font size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM