Created
November 2, 2017 11:51
-
-
Save alyssaq/90af455d02e9641bd139f15c5576ec79 to your computer and use it in GitHub Desktop.
Different y scales with datetime x-axis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
import datetime | |
t = datetime.datetime.now().date() | |
varr = range(10) | |
tarr = matplotlib.dates.date2num([t + datetime.timedelta(days=i) for i in varr]) | |
fig = plt.figure() | |
ax1 = fig.add_subplot(1,1,1) | |
ax1.plot(tarr, varr, 'r-') | |
ax2 = ax1.twinx() | |
ax2.plot_date(tarr, list(range(3, 13))[::-1], 'b.') | |
xfmt = mdates.DateFormatter('%d-%b %H:%M') | |
ax1.xaxis.set_major_formatter(xfmt) | |
fig.show() |
Author
alyssaq
commented
Nov 2, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment