-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems setting xticks #41
Comments
I have a similar problem. A minimal example is that, import matplotlib.pyplot as plt
import nc_time_axis
import numpy
import cftime
x = [nc_time_axis.CalendarDateTime(cftime.datetime(y, 1, 1), "360_day")
for y in range(2000, 2010)]
y = numpy.arange(10)
plt.scatter(x, y)
plt.show() only works if I believe the solution is to put the following here, if isinstance(value, np.ndarray) or isinstance(value, list): |
I think I'm having a similar problem here. There is an incompatibility between With a import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
import xarray as xr
times = np.arange('1990', '2000', dtype='datetime64[M]')
data = xr.DataArray(
np.random.rand(len(times)),
dims=['time'],
coords=[times]
)
f, ax = plt.subplots()
ax.plot(data.time, data)
ax.xaxis.set_major_locator(mdates.YearLocator(2)) With a import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
import xarray as xr
times = xr.cftime_range('1990', '2000', freq='M')
data = xr.DataArray(
np.random.rand(len(times)),
dims=['time'],
coords=[times]
)
f, ax = plt.subplots()
ax.plot(data.time, data)
ax.xaxis.set_major_locator(mdates.YearLocator(1)) |
@lukelbd, do you think this would be a relatively quick fix? This looks like a somewhat dead repo given how old this issue is. I am very unfamiliar with these locators. Would it just require a few lines of code in |
This might be a pretty big PR unfortunately, but shouldn't be very conceptually complicated. You basically need to copy + modify If you have time go for it, but otherwise it might make more sense to convert your |
Oh, now I see the specific issue at the top is different and possibly easier to fix. The user was trying to manually set the tick locations by sending a Since this repo has had no commits for >1 year I'd be open to just adding the entire repo's codebase to proplot. Definitely fits within proplot's scope of easier plotting/xarray integration. But that's a long term goal... maybe this summer. |
The issue in @MartinDix's initial comment is a symptom of the issue identified in #79 (comment): the This is OK. I propose working around this in nc-time-axis in the following way:
To make the analogy with matplotlib clear, I might suggest renaming Does anyone in @SciTools/nc-time-axis-devs or this issue have any thoughts on this proposal? |
See #84 for a proof of concept. |
The proposal in #41 (comment) has been implemented in #84. See the PR description for an example of using the new |
Consider the following modification of the basic example
This works, but the tick marks are slightly oddly located. If I try to add ticks with
I get an error
This seems to be because convert checks whether its argument is a numpy array but doesn't handle lists properly.
Using
fails with
It seems that ndays is needed for working out the formatting of tick labels but isn't set when using explicit locations.
At the moment I'm using an ugly workaround that gets the locator and sets the ndays attribute. E.g,
Versions are matplotlib 3.0.2, cftime 1.0.3.4, nc_time_axis 1.1.0.
The text was updated successfully, but these errors were encountered: