Hi list, Hi Gökhan,
I once more would like to say that I like the 2 new features introduced by
Gökhan (key 'k' for xscaling and the generalized handling of the key-mapping,
which allows the user to choose its prefered key for a certain task) and I'd
like to see this in matplotlib.
I attached a patch (against todays svn) of my final version, which is a
slightly modified version of Gökhans patch.
If anybody could test it and comments on this I'd be happy. Otherwise I will
place the patch on the patch tracker in (let's say) a week.
Thanks in advance for any help in order to bring this into matplotlib.
Kind regards,
Matthias
On Tuesday 02 February 2010 14:05:52 Matthias Michler wrote:
> Hi Gökhan,
>
> I'm sorry I didn't had the time to look into your patch in the last days.
>
> Today I did have a look at it and in my opinion you did a great job -
> Thanks! The point is that I'm not a developer and therefore cannot commit
> it right away ;-) .
>
> Although it is great stuff I tried to even improve it. Attached you find my
> svn-diff of the backend_bases.py, where I tried to get rid of the different
> handling of *3* keys for home and *1* for save etc. I converted all
> key-maps into lists and therefore the number of keys doesn't matter. With
> that I can do also
> xscale : L, k
> in my matplotlibrc and allow foGökhanr both of our favorite keys for the
toggling
> of the xscale ;-)
>
> Concerning the names of the variables you find some changes in the attached
> patch, which are not yet complete in my opinion, but I didn't want to spoil
> your lines to much. If I have to decide between short and meaningful
> variable names, I prefer meaningful at least if they don't blow up to 80
> chars ;-) ...
>
> In my opinion your next patch should be a part of matplotlibs svn, but as I
> mentioned above I'm just a user. In case I can help you somehow in bringing
> up this patch, don't hesitate to write again and hopefully I have the time
> to help.
>
> Kind regards,
> Matthias
>
> On Friday 29 January 2010 20:22:20 Gökhan Sever wrote:
> > My initial patch is ready for your review.
> >
> > I tested with latest svn and customized key-mapping (from matplotlibrc)
> > is working correctly.
> >
> > Please review, and let me know if there would be any better solution,
> > variable naming, placing etc.. I can also update the
> > http://matplotlib.sourceforge.net/users/navigation_toolbar.html
> > accordingly.
> >
> > On Mon, Jan 25, 2010 at 12:58 PM, Gökhan Sever
<gokhanse...@gmail.com>wrote:
> > > Hello,
> > >
> > > I could these keys into rcsetup.py file as well as
> > > matplotlibrc.template and update backend_bases.py accordingly. And add
> > > some documentation reflecting
> > > the changes made.
> > >
> > > # Event keys to interact with figures/plots via keyboard
> > >
> > > fullscreen : 'f'
> > > home : 'h'
> > > reset : 'r'
> > > back : 'c'
> > > forward : 'v'
> > > pan : 'p'
> > > zoom : 'o'
> > > save : 's'
> > > grid : 'g'
> > > yscale : 'l'
> > > xscale : 'k'
> > >
> > >
> > > *Notes:*
> > >
> > > Matthias, leaving values as empty will remove the key short-cut.
> > >
> > > Don't understand exactly what 'a' does?
> > >
> > > f doesn't toggle full-screen --using qt4agg backend.
> > >
> > > There are a couple function duplicates. (eg. back with 'c' and left and
> > > backspace keys. How can represent them? Create a list inside the
> > > dictionary?
> > > back = ['c', 'left', 'backspace']
> > >
> > > 'o' seems like unnecessary. Since you have to select an area using
> > > mouse.
> > >
> > > 's' doesn't behave correctly here. Shouldn't it bring the save dialog?
> > > Instead I am getting:
> > > TypeError: save_figure() takes exactly 1 argument (2 given)
> > >
> > >
> > >
> > > On Mon, Jan 25, 2010 at 8:32 AM, Matthias Michler
> > > <matthiasmich...@gmx.net
> > >
> > > > wrote:
> > >>
> > >> Hi Gökhan,
> > >>
> > >> I just wanted to discuss the key, because I think this patch should be
> > >> part of
> > >> matplotlib and not only of individual users. I think it is worth be be
> > >> added
> > >> to the mpl-tracker at http://sourceforge.net/tracker/?group_id=80706
> > >> or maybe
> > >> one of the developers has the time to commit this small change?
> > >>
> > >> I think your idea about key-mappings in the matplotlib-rc is a good
> > >> option to
> > >> customize keyboard short cuts and even remove short-cuts which aren't
> > >> of intrest for the individual user. Furthermore the latter yields
> > >> space for keyboard shortcuts, which are used in one's own program.
> > >>
> > >> Kind regards,
> > >> Matthias
> > >>
> > >> On Friday 22 January 2010 16:57:22 Gökhan Sever wrote:
> > >> > It is very simple to change key-assignment. Take a look at the
> > >> > backend_bases.py code (search for event.key instances) :
> > >> >
> > >> > elif event.key == 'L':
> > >> >
> > >> > I was thinking to move y-scaling to "y" and x-scaling to "x" but x
> > >> > and y are assigned to something else (
> > >> > http://matplotlib.sourceforge.net/users/navigation_toolbar.html)
> > >> >
> > >> > For me toggling "k" is simpler for me than doing Shift-L.
> > >> >
> > >> > Maybe these options could be provided in the matplotlibrc file.
> > >> > Users
> > >>
> > >> can
> > >>
> > >> > make their key mapping based on their choice. That requires some
> > >> > more coding
> > >> >
> > >> > :)
> > >> >
> > >> > On Fri, Jan 22, 2010 at 1:59 AM, Matthias Michler
> > >> >
> > >> > <matthiasmich...@gmx.net>wrote:
> > >> > > Hi Gökhan, Hi list members,
> > >> > >
> > >> > > This is really a missing feature in matplotlib in my opinion and
> > >> > > it's great that you took the time to make an suggestion, but I
> > >> > > would prefer capital "L"
> > >> > > for the xaxis-scaling like gnuplot although I'm not sure this is
> > >> > > possible.
> > >> > >
> > >> > > What do you and other list members think about that?
> > >> > >
> > >> > > Kind regards,
> > >> > > Matthias
> > >> > >
> > >> > > On Thursday 21 January 2010 19:45:37 Gökhan Sever wrote:
> > >> > > > Hello,
> > >> > > >
> > >> > > > "l" key does the log - linear scaling for y-axis. I have made a
> > >>
> > >> minor
> > >>
> > >> > > > change to use "k" for x-axis scaling.
> > >> > > >
> > >> > > > Patch added. Feel free to add if you find it useful.
Index: matplotlibrc.template
===================================================================
--- matplotlibrc.template (revision 8139)
+++ matplotlibrc.template (working copy)
@@ -360,3 +360,20 @@
# from matplotlib import verbose.
#verbose.level : silent # one of silent, helpful, debug, debug-annoying
#verbose.fileo : sys.stdout # a log filename, sys.stdout or sys.stderr
+
+# Event keys to interact with figures/plots via keyboard.
+# Customize these settings according to your needs.
+# Leave the field(s) empty if you don't need a key-map. (i.e., fullscreen : '')
+
+#fullscreen : f # toggling
+#home : h, r, home # home or reset mnemonic
+#back : left, c, backspace # forward / backward keys to enable
+#forward : right, v # left handed quick navigation
+#pan : p # pan mnemonic
+#zoom : o # zoom mnemonic
+#save : s # saving current figure
+#grid : g # switching on/off a grid in current axes
+#yscale : l # toggle scaling of y-axes ('log <-> 'linear')
+#xscale : L, k # toggle scaling of x-axes ('log <-> 'linear')
+#all_axes : a # enable all axes
+
Index: lib/matplotlib/backend_bases.py
===================================================================
--- lib/matplotlib/backend_bases.py (revision 8139)
+++ lib/matplotlib/backend_bases.py (working copy)
@@ -1888,50 +1888,92 @@
# self.destroy() # how cruel to have to destroy oneself!
# return
- if event.key == 'f':
+ # Load key-mappings from your matplotlibrc file.
+ fullscreen_keys = rcParams['fullscreen']
+ home_keys = rcParams['home']
+ back_keys = rcParams['back']
+ forward_keys = rcParams['forward']
+ pan_keys = rcParams['pan']
+ zoom_keys = rcParams['zoom']
+ save_keys = rcParams['save']
+ grid_keys = rcParams['grid']
+ toggle_yscale_keys = rcParams['yscale']
+ toggle_xscale_keys = rcParams['xscale']
+ all = rcParams['all_axes']
+
+ # to get a common standard we move all keys for each action into a list
+ for key in [fullscreen_keys, home_keys, back_keys, forward_keys,
+ pan_keys, zoom_keys, save_keys, grid_keys,
+ toggle_xscale_keys, toggle_yscale_keys, all]:
+ if type(key) is not list:
+ key = list(key)
+
+ # toggle fullscreen mode (default key 'f')
+ if event.key in fullscreen_keys:
self.full_screen_toggle()
- # *h*ome or *r*eset mnemonic
- elif event.key == 'h' or event.key == 'r' or event.key == "home":
+ # home or reset mnemonic (default key 'h', 'home' and 'r')
+ elif event.key in home_keys:
self.canvas.toolbar.home()
- # c and v to enable left handed quick navigation
- elif event.key == 'left' or event.key == 'c' or event.key == 'backspace':
+ # forward / backward keys to enable left handed quick navigation
+ # (default key for backward: 'left', 'backspace' and 'c')
+ elif event.key in back_keys:
self.canvas.toolbar.back()
- elif event.key == 'right' or event.key == 'v':
+ # (default key for forward: 'right' and 'v')
+ elif event.key in forward_keys:
self.canvas.toolbar.forward()
- # *p*an mnemonic
- elif event.key == 'p':
+ # pan mnemonic (default key 'p')
+ elif event.key in pan_keys:
self.canvas.toolbar.pan()
- # z*o*om mnemonic
- elif event.key == 'o':
+ # zoom mnemonic (default key 'o')
+ elif event.key in zoom_keys:
self.canvas.toolbar.zoom()
- elif event.key == 's':
+ # saving current figure (default key 's')
+ elif event.key in save_keys:
self.canvas.toolbar.save_figure(self.canvas.toolbar)
if event.inaxes is None:
return
# the mouse has to be over an axes to trigger these
- if event.key == 'g':
+ # switching on/off a grid in current axes (default key 'g')
+ if event.key in grid_keys:
event.inaxes.grid()
self.canvas.draw()
- elif event.key == 'l':
+ # toggle scaling of y-axes between 'log and 'linear' (default key 'l')
+ elif event.key in toggle_yscale_keys:
ax = event.inaxes
scale = ax.get_yscale()
- if scale=='log':
+ if scale == 'log':
ax.set_yscale('linear')
ax.figure.canvas.draw()
- elif scale=='linear':
+ elif scale == 'linear':
ax.set_yscale('log')
ax.figure.canvas.draw()
+ # toggle scaling of x-axes between 'log and 'linear' (default key 'k')
+ elif event.key in toggle_xscale_keys:
+ ax = event.inaxes
+ scalex = ax.get_xscale()
+ if scalex == 'log':
+ ax.set_xscale('linear')
+ ax.figure.canvas.draw()
+ elif scalex == 'linear':
+ ax.set_xscale('log')
+ ax.figure.canvas.draw()
- elif event.key is not None and (event.key.isdigit() and event.key!='0') or event.key=='a':
- # 'a' enables all axes
- if event.key!='a':
- n=int(event.key)-1
+ elif event.key is not None and \
+ (event.key.isdigit() and event.key!='0') or event.key in all:
+ # keys in list 'all' enables all axes (default key 'a'),
+ # otherwise if key is a number only enable this particular axes
+ # if it was the axes, where the event was raised
+ if not (event.key in all):
+ n = int(event.key)-1
for i, a in enumerate(self.canvas.figure.get_axes()):
- if event.x is not None and event.y is not None and a.in_axes(event):
- if event.key=='a':
+ # consider axes, in which the event was raised
+ # FIXME: Why only this axes?
+ if event.x is not None and event.y is not None \
+ and a.in_axes(event):
+ if event.key in all:
a.set_navigate(True)
else:
a.set_navigate(i==n)
Index: lib/matplotlib/rcsetup.py
===================================================================
--- lib/matplotlib/rcsetup.py (revision 8139)
+++ lib/matplotlib/rcsetup.py (working copy)
@@ -546,9 +546,22 @@
'path.simplify' : [True, validate_bool],
'path.simplify_threshold' : [1.0 / 9.0, ValidateInterval(0.0, 1.0)],
- 'agg.path.chunksize' : [0, validate_int] # 0 to disable chunking;
- # recommend about 20000 to
- # enable. Experimental.
+ 'agg.path.chunksize' : [0, validate_int], # 0 to disable chunking;
+ # recommend about 20000 to
+ # enable. Experimental.
+ # key-mappings
+ 'fullscreen' : ['f', str],
+ 'home' : [['h', 'r', 'home'], validate_stringlist],
+ 'back' : [['left', 'c', 'backspace'], validate_stringlist],
+ 'forward' : [['right', 'v'], validate_stringlist],
+ 'pan' : ['p', str],
+ 'zoom' : ['o', str],
+ 'save' : ['s', str],
+ 'grid' : ['g', str],
+ 'yscale' : ['l', str],
+ 'xscale' : ['k', str],
+ 'all_axes' : ['a', str]
+
}
if __name__ == '__main__':
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users