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.
python plot axis
add a comment |
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.
python plot axis
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
add a comment |
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.
python plot 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.
python plot axis
python plot axis
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 24 '18 at 12:43
Wojtek SzczęsnyWojtek Szczęsny
54
54
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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