Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

pyplot.plotfile. gridon option added with default from rcParam. #1297

Merged
merged 1 commit into from

4 participants

@montefra

This should be a clean pull request of issue: #1205

Recap: the original plotfile function draw the axes grids at each call. This pull request implements a
keywords to enable or disable the grid. The default is taken from rc.Params['axes.gris'].
This keyword is deprecated and will be deleted from future releases

@dmcdougall
Collaborator

Thanks for that, @montefra. If you ever need to update this pull request you can do the following:

1) Make sure you are currently on the plotfile_grid branch:

git checkout plotfile_grid

2) Make any changes you want:

git add ...
git commit

3) Push the branch:

git push origin plotfile_grid

The updates will display here automagically.

@dmcdougall
Collaborator

@efiring You had concerns about this change hurting users. Would an entry in api_changes.rst address those concerns, or would a warning be more appropriate?

lib/matplotlib/pyplot.py
@@ -2189,8 +2192,7 @@ def getname_val(identifier):
elif i==1:
ax = fig.add_subplot(1,1,1)
- ax.grid(True)
-
+ ax.grid(gridon)
@dmcdougall Collaborator

I think you lost some indentation here.

I thought that too. But if you go to my repository (https://github.com/montefra/matplotlib/blob/plotfile_grid/lib/matplotlib/pyplot.py) ax.grid(gridon) has the right indentation.
Can be a problem with tabs. I use vim with some selfindent and it seems that it converts spaces to tabs when they are many.
I've tested the code before submitting and didn't get any indent error. I can substitute the tab with spaces and recommit if it's a problem.

@WeatherGod Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@efiring
Owner

This is very confusing, despite being a tiny change. From reading the predecessor, #1205, I gathered that the decision was to just make the jump: leave out the new kwarg, and use the rcParams value internally, for consistency with other plotting. However, this PR has the kwarg back in. Furthermore, it is used in a particularly confusing way, such that only the rcParams value at the time the function is defined takes effect; changing the rcParams value before the function is called will not affect the function:

In [1]: x = dict(a=1)

In [2]: def f(xx=x['a']):
   ...:     print xx
   ...:     

In [3]: f()
1

In [4]: x['a'] = 2

In [5]: f()
1

It looks like the best way to handle this is going to be to make a clean break--knowing it may cause some presumably minor breakage (changing plot appearance, not information content) in user code. So I think we need to leave the kwarg out, and simply use the rcParams value internally. This requires a note in api_changes.

If @mdboom or others would prefer not to make this api change (which is almost a bug fix; it is repairing a design flaw in plotfile) for v1.2, then it (meaning not the present PR, but the tiny change outlined above, as a clean single changeset to whichever version is selected as the target) can be targeted to master instead. It's not urgent.

@dmcdougall
Collaborator

@montefra Could you update this to be in line with @efiring's suggestion?

@montefra

@dmcdougall: gridon removed. I also think that is neater if plotfile works as all the other pyplot functions
@efiring :+1: I didn't know that function arguments are evaluated a definition time, not at execution time.

@dmcdougall
Collaborator

@montefra You'll also need to add a little note in api_changes.rst warning users of the new behaviour.

Edit: grammar.

@montefra

@dmcdougall done. I hope the the English is good enough

@dmcdougall
Collaborator

@montefra Thanks. Can you squash all this down to a single commit?

@montefra

@dmcdougall done without making a mess.

@dmcdougall dmcdougall merged commit f1dbe0e into matplotlib:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 5 deletions.
  1. +5 −0 doc/api/api_changes.rst
  2. +1 −5 lib/matplotlib/pyplot.py
View
5 doc/api/api_changes.rst
@@ -15,6 +15,11 @@ For new features that were added to matplotlib, please see
Changes in 1.3.x
================
+* Removed call of :meth:`~matplotlib.axes.Axes.grid` in
+ :meth:`~matplotlib.pyplot.plotfile`. To draw the axes grid, set to *True*
+ matplotlib.rcParams['axes.grid'] or ``axes.grid`` in ``.matplotlibrc`` or
+ explicitly call :meth:`~matplotlib.axes.Axes.grid`
+
* A new keyword *extendrect* in :meth:`~matplotlib.pyplot.colorbar` and
:class:`~matplotlib.colorbar.ColorbarBase` allows one to control the shape
of colorbar extensions.
View
6 lib/matplotlib/pyplot.py
@@ -2101,8 +2101,7 @@ def polar(*args, **kwargs):
def plotfile(fname, cols=(0,), plotfuncs=None,
comments='#', skiprows=0, checkrows=5, delimiter=',', names=None,
- subplots=True, newfig=True,
- **kwargs):
+ subplots=True, newfig=True, **kwargs):
"""
Plot the data in in a file.
@@ -2198,9 +2197,6 @@ def getname_val(identifier):
elif i==1:
ax = fig.add_subplot(1,1,1)
- ax.grid(True)
-
-
yname, y = getname_val(cols[i])
ynamelist.append(yname)
Something went wrong with that request. Please try again.