Comments (5)
Perhaps it says something about the nature of these tests I added in #84, but I tested things locally and, as written, they fail if I do not use matplotlib.use("agg")
. For example:
___________________________________ test_set_ticks_with_CFTimeFormatter[List[CalendarDateTime]-x] ___________________________________
axis = 'x', ticks = [<CalendarDateTime: datetime=1986-02-01 00:00:00, calendar={self.calendar}>]
@pytest.mark.parametrize("axis", ["x", "y"])
@pytest.mark.parametrize("ticks", TICKS.values(), ids=list(TICKS.keys()))
def test_set_ticks_with_CFTimeFormatter(axis, ticks):
times = [cftime.Datetime360Day(1986, month, 30) for month in range(1, 6)]
data = range(len(times))
fig, ax = plt.subplots(1, 1)
formatter = nc_time_axis.CFTimeFormatter("%Y-%m", "360_day")
if axis == "x":
ax.plot(times, data)
ax.set_xticks(ticks)
ax.xaxis.set_major_formatter(formatter)
fig.canvas.draw()
ticklabels = ax.get_xticklabels()
else:
ax.plot(data, times)
ax.set_yticks(ticks)
ax.yaxis.set_major_formatter(formatter)
fig.canvas.draw()
ticklabels = ax.get_yticklabels()
result_labels = [label.get_text() for label in ticklabels]
expected_labels = ["1986-02"]
> assert result_labels == expected_labels
E AssertionError: assert [''] == ['1986-02']
E At index 0 diff: '' != '1986-02'
E Full diff:
E - ['']
E + ['1986-02']
nc_time_axis/tests/integration/test_plot.py:139: AssertionError
It appears in order to get these tests to pass I need to use plt.show()
instead of fig.canvas.draw()
when using a GUI backend. This results in a GUI plot showing up for each test, which I need to close by hand before the testing code continues (not ideal).
Testing that the tick labels were set appropriately is a bit of a tricky problem. The solution I used came from this StackOverflow answer, but perhaps there is a more robust way. In lieu of a better approach, I would say based on @rcomer's comment -- #66 (comment) -- and my experience here that I would be inclined to keep matplotlib.use("agg")
for now.
from nc-time-axis.
There is of course no harm at all in leaving it in, and if it causes issues by removing there is no reason to do so. So feel free to ignore my comment below.
I was interested to see if I could reproduce your issue and wasn't able - I tried a small example with ipython and a small test and both worked for me as expected (see below). But I only use matplotlib proper - is this something nc-time-axis specific? Or what version of mpl do you use?
in ipython:
In [1]: import matplotlib.pyplot as plt
In [2]: fig, ax = plt.subplots(1, 1)
In [3]: x = [1, 2, 3]
In [4]: y = [4, 5, 6]
In [5]: ax.plot(x, y)
In [6]: ax.get_xticklabels()
Out[6]:
[Text(0, 0, ''),
...]
In [7]: fig.canvas.draw()
In [8]: ax.get_xticklabels()
Out[8]:
[Text(0.75, 0, '0.75'),
...]
using pytest:
import warnings
import matplotlib.pyplot as plt
def test_ticklabels():
fig, ax = plt.subplots(1, 1)
x = [1, 2, 3]
y = [4, 5, 6]
ax.plot(x, y)
warnings.warn(str(ax.get_xticklabels()))
fig.canvas.draw()
warnings.warn(str(ax.get_xticklabels()))
from nc-time-axis.
Very interesting. I'm using matplotlib version 3.4.3. I can reproduce your example in an IPython shell, but not if I convert it to a script. I also get empty labels both times if I use your pytest example. Locally matplotlib chooses to use the "MacOSX"
backend for me -- maybe you are using a different backend?
from nc-time-axis.
I am on linux and it selects Qt5Agg
. Yes that seems to be a bug of the "MacOSX"
backend: matplotlib/matplotlib#19197 & matplotlib/matplotlib#19268
from nc-time-axis.
Ah I didn't see those issues -- thanks! I think that is probably enough to convince me that we should stick with matplotlib.use("agg")
.
from nc-time-axis.
Related Issues (20)
- Add citation information? HOT 14
- Implement a cftime-compatible version of matplotlib's `ConciseDateFormatter`
- Add an example of a(n horribly) wrong plot when NOT using nc-time-axis HOT 5
- Request for contributor ORCIDs HOT 9
- how to best set lim? // allow string in `convert`? HOT 3
- small change to tests needed for upcoming cftime 1.3.0 release HOT 2
- Cannot import nc_time_axis (v1.2.0, python v3.8.5, conda environment) HOT 1
- New minor release? HOT 5
- New cftime 1.5.0 breaks nc-time-axis HOT 1
- Documentation HOT 2
- Reboot nc-time-axis
- nc-time-axis==1.3.1 impossible to install with scitools-iris==3.0.2 HOT 14
- `nc-time-axis` dates don't work with `plt.fill_between(...)` HOT 5
- Enable plotting of now calendar-aware `cftime.datetime` objects HOT 1
- Deprecate `CalendarDateTime`? HOT 1
- Update requirements
- Switch internal time units to microseconds
- `NetCDFDateTimeLocator.min_n_ticks` not used
- matplotlib deprecates munits.ConversionInterface.is_numlike
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nc-time-axis.