How to change the ticks on x-axis?












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.










share|improve this question




















  • 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)].

    – teng
    Nov 24 '18 at 1:24
















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.










share|improve this question




















  • 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)].

    – teng
    Nov 24 '18 at 1:24














0












0








0


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.










share|improve this question
















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.







python plot axis






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 0:16









Lee Mac

3,91131339




3,91131339










asked Nov 23 '18 at 23:56









Wojtek SzczęsnyWojtek Szczęsny

54




54








  • 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)].

    – teng
    Nov 24 '18 at 1:24














  • 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)].

    – teng
    Nov 24 '18 at 1:24








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)].

– teng
Nov 24 '18 at 1:24





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)].

– teng
Nov 24 '18 at 1:24












1 Answer
1






active

oldest

votes


















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.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454023%2fhow-to-change-the-ticks-on-x-axis%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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.






    share|improve this answer




























      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.






      share|improve this answer


























        0












        0








        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 12:43









        Wojtek SzczęsnyWojtek Szczęsny

        54




        54






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454023%2fhow-to-change-the-ticks-on-x-axis%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...