Datetime axis format fixed to %Y-%m-%d
asbjos opened this issue · 4 comments
asbjos commented
Hi, and thanks for the great package.
On version 0.4.2 (by the way, the .__version__
attribute is not defined), I want to plot with a broken y-axis, and datetime objects on the x-axis.
import numpy as np
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
import datetime
startTime = datetime.datetime(2021, 8, 6, 11, 1, 20)
timeLength = 8
endTime = startTime + datetime.timedelta(seconds=timeLength)
timeStep = 0.01
fig = plt.figure()
bax = brokenaxes(
ylims=(
(-1.1,-0.9),
(0.9, 1.1)
),
xlims=(
(startTime, endTime),
)
)
x = np.arange(0,timeLength, timeStep)
y = np.cos(x)
datex = np.arange(startTime, endTime, datetime.timedelta(seconds=timeStep))
bax.plot(datex,y)
fig.autofmt_xdate()
[dh.remove() for dh in bax.diag_handles]
bax.draw_diags()
I get the default %Y-%m-%d date format.
As I plot over just 8 seconds, I want to format to %M:%S.
But I can't get it to reformat. Is this at all supported?
import numpy as np
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
import datetime
import matplotlib.dates as mdates
startTime = datetime.datetime(2021, 8, 6, 11, 1, 20)
timeLength = 8
endTime = startTime + datetime.timedelta(seconds=timeLength)
timeStep = 0.01
fig = plt.figure()
bax = brokenaxes(
ylims=(
(-1.1,-0.9),
(0.9, 1.1)
),
xlims=(
(startTime, endTime),
)
)
x = np.arange(0,timeLength, timeStep)
y = np.cos(x)
datex = np.arange(startTime, endTime, datetime.timedelta(seconds=timeStep))
bax.plot(datex,y)
fig.autofmt_xdate()
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%M:%S')) # not doing anything
[dh.remove() for dh in bax.diag_handles]
bax.draw_diags()
bendichter commented
import numpy as np
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
import datetime
import matplotlib.dates as mdates
startTime = datetime.datetime(2021, 8, 6, 11, 1, 20)
timeLength = 8
endTime = startTime + datetime.timedelta(seconds=timeLength)
timeStep = 0.01
fig = plt.figure()
bax = brokenaxes(
ylims=(
(-1.1,-0.9),
(0.9, 1.1)
),
xlims=(
(startTime, endTime),
)
)
x = np.arange(0,timeLength, timeStep)
y = np.cos(x)
datex = np.arange(startTime, endTime, datetime.timedelta(seconds=timeStep))
bax.plot(datex,y)
bax.axs[1].xaxis.set_major_formatter(mdates.DateFormatter('%M:%S'))
asbjos commented
Ah, thanks!
Is there any documentation that explains this, so that I don't have to bother you with this stuff? Or is the readme the only intended documentation?
bendichter commented