Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
WIP: Lockout new converters Part 2 #9776
This version, which supplants #9736 makes an axis only have a
Still a WIP, but posting to help w/ #9774
Now changed so that the first units used are set for the axis, and further convert calls are sent to the same converter. If the converter wants to handle the data type it can. This makes mixed-use calls, i.e.
ax.plot(['a', 'b', 'c']) ax.plot([1, 'd', 3])
work so long as the converter can handle the data in the second call.
Helps issues like #10147
import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates import datetime base = datetime.datetime.today() time = [base - datetime.timedelta(days=x) for x in range(0, 3)] data = np.random.rand( 3) fig, ax = plt.subplots(tight_layout=True) ax.set_ylim(time, time) ax.plot( data, time)
fig, ax = plt.subplots(tight_layout=True) ax.set_ylim(0., 1.) ax.plot( data, time)
This version doesn't lockout data that would be registered by new data, it just uses the original converter first registered for the axis. Its up to the converter to handle the new data.
For instance, if we call:
base = datetime.datetime(2017, 1, 1, 2, 3, 10) time = [base + datetime.timedelta(days=x) for x in range(0, 3)] ax.plot([1., 2.], [1., 3.]) ax.plot(time)
the call will fail. But:
base = datetime.datetime(2017, 1, 1, 2, 3, 10) time = [base + datetime.timedelta(days=x) for x in range(0, 3)] ax.plot(time) ax.plot([1., 2.], np.array([1., 3.]) + 736330)
As we discussed after today's meeting: I think that any lockout machinery should apply only to converters, not to the native floats to which unitized quantities are converted for plotting. For example, in making a plot of categoricals, one should remain able to place lines or any other artists on the Axes using native floats. Similarly, one should remain able to plot Datetimes and mpl datenums on the same Axes. This should be possible regardless of the order in which artists are added.
@efiring, just to rephrase: the converter would be locked to the axis. However, the converter could still choose to deal w/ floats in a self-consistent way. So, the datetime converter could still be set to allow floats through, however, it might perform its own checks on them.
What that would preclude however, is calling