0

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:

image plt.hist

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.

Community
  • 1
  • 1
  • 1
    the stack trace is telling you to convert the items from int to string, i.e. `['{:d}'.format(x) for x in np.arange(0,10,1)]`. – pangyuteng Nov 24 '18 at 01:24

1 Answers1

0

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.