Plotting time in x axis using matplotlib
I have the following dataset:
pressuredfjan1[['Unit','Time1']].head()
Out[53]:
Unit Time1
0 321.3599 1970-01-01 00:00:40
1 321.3599 1970-01-01 00:04:40
2 321.6651 1970-01-01 00:06:40
3 320.7496 1970-01-01 00:10:40
4 322.2755 1970-01-01 00:14:40
I am trying to plot Unit
against Time1
in an HH:MM:SS format.
I've tried the following code:
dates = dates.date2num(list(pressuredfjan1['Time1']))
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
ax1.plot(dates,pressuredfjan1['Unit'])
plt.show()
This gives me the plot, but I am not getting HH:MM:SS format in the x-axis. Instead, I'm getting 3.1, 3.2, 3.4...Le14 etc. Can somebody help me out here please? Thanks.
python datetime matplotlib timedelta
add a comment |
I have the following dataset:
pressuredfjan1[['Unit','Time1']].head()
Out[53]:
Unit Time1
0 321.3599 1970-01-01 00:00:40
1 321.3599 1970-01-01 00:04:40
2 321.6651 1970-01-01 00:06:40
3 320.7496 1970-01-01 00:10:40
4 322.2755 1970-01-01 00:14:40
I am trying to plot Unit
against Time1
in an HH:MM:SS format.
I've tried the following code:
dates = dates.date2num(list(pressuredfjan1['Time1']))
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
ax1.plot(dates,pressuredfjan1['Unit'])
plt.show()
This gives me the plot, but I am not getting HH:MM:SS format in the x-axis. Instead, I'm getting 3.1, 3.2, 3.4...Le14 etc. Can somebody help me out here please? Thanks.
python datetime matplotlib timedelta
add a comment |
I have the following dataset:
pressuredfjan1[['Unit','Time1']].head()
Out[53]:
Unit Time1
0 321.3599 1970-01-01 00:00:40
1 321.3599 1970-01-01 00:04:40
2 321.6651 1970-01-01 00:06:40
3 320.7496 1970-01-01 00:10:40
4 322.2755 1970-01-01 00:14:40
I am trying to plot Unit
against Time1
in an HH:MM:SS format.
I've tried the following code:
dates = dates.date2num(list(pressuredfjan1['Time1']))
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
ax1.plot(dates,pressuredfjan1['Unit'])
plt.show()
This gives me the plot, but I am not getting HH:MM:SS format in the x-axis. Instead, I'm getting 3.1, 3.2, 3.4...Le14 etc. Can somebody help me out here please? Thanks.
python datetime matplotlib timedelta
I have the following dataset:
pressuredfjan1[['Unit','Time1']].head()
Out[53]:
Unit Time1
0 321.3599 1970-01-01 00:00:40
1 321.3599 1970-01-01 00:04:40
2 321.6651 1970-01-01 00:06:40
3 320.7496 1970-01-01 00:10:40
4 322.2755 1970-01-01 00:14:40
I am trying to plot Unit
against Time1
in an HH:MM:SS format.
I've tried the following code:
dates = dates.date2num(list(pressuredfjan1['Time1']))
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
ax1.plot(dates,pressuredfjan1['Unit'])
plt.show()
This gives me the plot, but I am not getting HH:MM:SS format in the x-axis. Instead, I'm getting 3.1, 3.2, 3.4...Le14 etc. Can somebody help me out here please? Thanks.
python datetime matplotlib timedelta
python datetime matplotlib timedelta
edited Nov 14 '18 at 10:00
Joe
5,96421329
5,96421329
asked Nov 14 '18 at 7:23
IndigoChildIndigoChild
340212
340212
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use:
import matplotlib as mpl
pressuredfjan1['dates'] = pd.to_datetime(pressuredfjan1['Time1']).dt.strftime('%H:%M:%S')
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
majorFormatter = mpl.dates.DateFormatter('%H:%M:%S')
ax1.xaxis.set_major_formatter(majorFormatter)
plt.plot_date(pressuredfjan1['dates'], pressuredfjan1['Unit'])
plt.show()
Thanks a lot ! :)
– IndigoChild
Nov 14 '18 at 9:30
You aer welcome! :)
– Joe
Nov 14 '18 at 9:30
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%2f53294998%2fplotting-time-in-x-axis-using-matplotlib%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
You can use:
import matplotlib as mpl
pressuredfjan1['dates'] = pd.to_datetime(pressuredfjan1['Time1']).dt.strftime('%H:%M:%S')
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
majorFormatter = mpl.dates.DateFormatter('%H:%M:%S')
ax1.xaxis.set_major_formatter(majorFormatter)
plt.plot_date(pressuredfjan1['dates'], pressuredfjan1['Unit'])
plt.show()
Thanks a lot ! :)
– IndigoChild
Nov 14 '18 at 9:30
You aer welcome! :)
– Joe
Nov 14 '18 at 9:30
add a comment |
You can use:
import matplotlib as mpl
pressuredfjan1['dates'] = pd.to_datetime(pressuredfjan1['Time1']).dt.strftime('%H:%M:%S')
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
majorFormatter = mpl.dates.DateFormatter('%H:%M:%S')
ax1.xaxis.set_major_formatter(majorFormatter)
plt.plot_date(pressuredfjan1['dates'], pressuredfjan1['Unit'])
plt.show()
Thanks a lot ! :)
– IndigoChild
Nov 14 '18 at 9:30
You aer welcome! :)
– Joe
Nov 14 '18 at 9:30
add a comment |
You can use:
import matplotlib as mpl
pressuredfjan1['dates'] = pd.to_datetime(pressuredfjan1['Time1']).dt.strftime('%H:%M:%S')
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
majorFormatter = mpl.dates.DateFormatter('%H:%M:%S')
ax1.xaxis.set_major_formatter(majorFormatter)
plt.plot_date(pressuredfjan1['dates'], pressuredfjan1['Unit'])
plt.show()
You can use:
import matplotlib as mpl
pressuredfjan1['dates'] = pd.to_datetime(pressuredfjan1['Time1']).dt.strftime('%H:%M:%S')
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
majorFormatter = mpl.dates.DateFormatter('%H:%M:%S')
ax1.xaxis.set_major_formatter(majorFormatter)
plt.plot_date(pressuredfjan1['dates'], pressuredfjan1['Unit'])
plt.show()
answered Nov 14 '18 at 7:55
JoeJoe
5,96421329
5,96421329
Thanks a lot ! :)
– IndigoChild
Nov 14 '18 at 9:30
You aer welcome! :)
– Joe
Nov 14 '18 at 9:30
add a comment |
Thanks a lot ! :)
– IndigoChild
Nov 14 '18 at 9:30
You aer welcome! :)
– Joe
Nov 14 '18 at 9:30
Thanks a lot ! :)
– IndigoChild
Nov 14 '18 at 9:30
Thanks a lot ! :)
– IndigoChild
Nov 14 '18 at 9:30
You aer welcome! :)
– Joe
Nov 14 '18 at 9:30
You aer welcome! :)
– Joe
Nov 14 '18 at 9:30
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%2f53294998%2fplotting-time-in-x-axis-using-matplotlib%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