From 38d83af6e5d02063eaac5d158eefbd0eca97e616 Mon Sep 17 00:00:00 2001 From: Federico Ariza Date: Fri, 11 Aug 2017 17:59:25 -0400 Subject: [PATCH 1/6] adding help tool --- lib/matplotlib/backend_tools.py | 67 +++++++++++++++++- lib/matplotlib/mpl-data/images/help.pdf | Bin 0 -> 1813 bytes lib/matplotlib/mpl-data/images/help.png | Bin 0 -> 472 bytes lib/matplotlib/mpl-data/images/help.ppm | Bin 0 -> 1741 bytes lib/matplotlib/mpl-data/images/help.svg | 52 ++++++++++++++ lib/matplotlib/mpl-data/images/help_large.png | Bin 0 -> 747 bytes lib/matplotlib/mpl-data/images/help_large.ppm | Bin 0 -> 6925 bytes lib/matplotlib/rcsetup.py | 1 + tools/make_icons.py | 3 +- 9 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 lib/matplotlib/mpl-data/images/help.pdf create mode 100644 lib/matplotlib/mpl-data/images/help.png create mode 100644 lib/matplotlib/mpl-data/images/help.ppm create mode 100644 lib/matplotlib/mpl-data/images/help.svg create mode 100644 lib/matplotlib/mpl-data/images/help_large.png create mode 100644 lib/matplotlib/mpl-data/images/help_large.ppm diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index 9c9249da8fb8..b444dfbcd41d 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -19,6 +19,8 @@ from matplotlib import rcParams from matplotlib._pylab_helpers import Gcf +from matplotlib.table import Table +import textwrap import matplotlib.cbook as cbook @@ -1020,6 +1022,68 @@ def _mouse_move(self, event): self.toolmanager.canvas.draw_idle() +class HelpTool(ToolToggleBase): + description = 'Print tool list, shortcuts and description' + default_keymap = rcParams['keymap.help'] + image = 'help.png' + + def __init__(self, *args): + ToolToggleBase.__init__(self, *args) + self.text_axes = None + + def enable(self, *args): + self.text_axes = self.figure.add_axes((0, 0, 1, 1)) + table = Table(self.text_axes, bbox=[0, 0, 1, 1]) + table.edges = 'B' + self.text_axes.add_table(table) + chars_in_width = self._find_chars_in_width(table.FONTSIZE) + + table.auto_set_font_size(False) + col_chars_width = int(chars_in_width / 4) - 2 + content = self._get_content(col_chars_width, col_chars_width, + 2 * col_chars_width) + for i, v in enumerate(content): + h = v[0] + table.add_cell(i, 0, text=v[1], width=1, height=h, loc='left', + fontproperties='monospace') + table.add_cell(i, 1, text=v[2], width=1, height=h, loc='left', + fontproperties='monospace') + table.add_cell(i, 2, text=v[3], width=2, height=h, loc='left', + fontproperties='monospace') + self.figure.canvas.draw_idle() + + def _find_chars_in_width(self, fontsize): + """Number of characters in figure width approx""" + # https://web.archive.org/web/20010717031241/plainlanguagenetwork.org/type/utbo211.htmhttps://web.archive.org/web/20010717031241/plainlanguagenetwork.org/type/utbo211.htm + # Approximately width = 60% of height for monospace fonts + charwidth = 0.6 * fontsize / 72.0 * self.figure.dpi + figwidth = self.figure.get_figwidth() * self.figure.dpi + return figwidth / charwidth + + def disable(self, *args): + self.text_axes.remove() + self.figure.canvas.draw_idle() + + def _get_content(self, w0, w1, w2): + rows = [(1, 'NAME', 'KEYS', 'DESCRIPTION')] + tools = self.toolmanager.tools + for name in sorted(tools): + if not tools[name].description: + continue + + keys = ', '.join(sorted(self.toolmanager.get_tool_keymap(name))) + name_lines = textwrap.wrap(name, w0) + keys_lines = textwrap.wrap(keys, w1) + desc_lines = textwrap.wrap(tools[name].description, w2) + # Height of the row is the maximum number of lines + height = max(len(name_lines), len(keys_lines), len(desc_lines)) + rows.append((height, + '\n'.join(name_lines), + '\n'.join(keys_lines), + '\n'.join(desc_lines))) + return rows + + default_tools = {'home': ToolHome, 'back': ToolBack, 'forward': ToolForward, 'zoom': ToolZoom, 'pan': ToolPan, 'subplots': 'ToolConfigureSubplots', @@ -1037,12 +1101,13 @@ def _mouse_move(self, event): _views_positions: ToolViewsPositions, 'cursor': 'ToolSetCursor', 'rubberband': 'ToolRubberband', + 'help': HelpTool } """Default tools""" default_toolbar_tools = [['navigation', ['home', 'back', 'forward']], ['zoompan', ['pan', 'zoom', 'subplots']], - ['io', ['save']]] + ['io', ['save', 'help']]] """Default tools in the toolbar""" diff --git a/lib/matplotlib/mpl-data/images/help.pdf b/lib/matplotlib/mpl-data/images/help.pdf new file mode 100644 index 0000000000000000000000000000000000000000..38178d05b2725addadec9f4c005a1a764f1096d1 GIT binary patch literal 1813 zcmah~3rtg27|x;&*NlgQIp+fpOyr?(AARsrCbX0x7+6799kAWo9%@~CZ+Ckk1!Wly zK^)V_f=*u9WH=GnA_7s7IY!X94HAtEG0rGNCr)t!2`YP?(^5e&*-ew%^W}e>^PT_u zu3xfB9ZZGDBz_IoK>cY61xUcN+azn&03w+&Kr5gTq5(u|js*fj$%u@JH-M-p3FP!R zFl<^vtWAtd5g8EznIlQfb0UyB{wFh{2n7zv@lrx03%o7`ir`(;N2Nyfp-lutyczY3 znS3iJ-|-+F5Gh+3y^%8jg(F>?#BPH+5ro={Pi==H5#T&PG{^Cx6}3S5O0*Top;fq} zK%Bs5SpYt!G6fJSm~GTSO&n^CR;dERSuKnJIbDwP0p}M$PD2;!p zLo!YfoqTDamCq7%h(OHHQvxxk)7ZnCaqd=aG$Dcjp*A4~RZz$45#foDGl*LOh3`d! z6Rn~E8MDN8)%CgxUO>DhN;u1|M$FuSoZ|JW~?D{OgttH!Qp6kHDK z?F);FYRzdo@{RkM_V4+ewt)%5L{nbZWAotsob6A>Mkap0b!&9={QZ$?`q6in=bi6% z-@$$S;a_hJxe^z4483}>@9)}@gFk43*0X69+_iv%hua4_Jmpqx!Il?GKa0G%JT9^Q zrHW;DO1;LnMgG?22kD`6x$D5M-W}s!{>{y4m!g-rwoGh~{8`s|D4hVarb;0=V#`T@$sb{M{UDz_`tE-9S z_vh9o_wG+mJEEx6?+iaTP-;>E?Ezai968gqtStLMRbl74m7CXkWcLf&hyq#Pk*bra zNx9ZzwYDv>r{u#sTNdBW@AuVJ&c7~=NvqmFy0FsdD@06Epbs6pYH4M)&}&EMq<+{`Gq@`H66X4b?Tqyk*@ut!TXkWtQp=I-UQt? zyNtS3Y^ZZ@e!K3tTTPGe#k}emms^KkDK$SH{L$ihx4m^!&xr@ajW<5=(O&td-(>-t z8BP?Cg{i(LTNbVG9?$nIVN1IAvdb6$F_dvndHmA77jjPpd6)PsZg1FiQkqfoX5MCx z1Gg>pkLDM>qj{LXE`O5d(NXf}h}WENm!)6+Vv#xHVdqCw@2TQ{`@`Ss8e3a?_95$1 zk2N|uFOzDu&k-Itxh&kNV64x{8JyA)7O-Dq4Zg&9<7Nx_s98NZMI_jBZBq-6y zb1H0H0jda^q(aFsil$^TQYH^3W&R}TA1EP|IF1)UfSD03CSEidSwM%7A#{j^w~8_a zEe+AbY;u)B$4VK-NslLz*zM)s@Wc|0L@ dD^4-yLPQuQ(JC^6Xr~Yz34I0qVw2R8{{W}EW2OKA literal 0 HcmV?d00001 diff --git a/lib/matplotlib/mpl-data/images/help.png b/lib/matplotlib/mpl-data/images/help.png new file mode 100644 index 0000000000000000000000000000000000000000..a52fbbe819e2fcbb1c1d5f8f143fc8d069688b3a GIT binary patch literal 472 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjEX7WqAsj$Z!;#Vf4nJ zFmC{1M)f27Yk`76C9V-A!TD(=<%vb947rIV1v&X8IhjccWvNBQnfZANMtTN%MtTML z#U&B&jPiK&SODM>mC86_nJR{Ht~oqG92>H6!I&RfjDz$oMC;uzx5 z`F6@iFJ?y(*Ymt}PEDaloIF?8a{Q9ydQ{(WW636gEnW(~S@jMA{|{;XY-~sp7Sx?) z(_PD*cq7Fqn~5u~VnhD4>hlKqn7%&t$}w@9Jpe7mLmAJ!PXuc{1r zO&`P;h<;ugBl>m0`&l*Y?r2IG3O2hD$$M@uho zwR_=Yy?RF7@zS@alxkN7wZ*W{x+i5|wE6s2##OJR_vU^TTHB|58yE`=p00i_>zopr E02Lj!oB#j- literal 0 HcmV?d00001 diff --git a/lib/matplotlib/mpl-data/images/help.ppm b/lib/matplotlib/mpl-data/images/help.ppm new file mode 100644 index 0000000000000000000000000000000000000000..aed6f506df4d1a3394aafff9b7b25899d49f500c GIT binary patch literal 1741 zcmWGA<1#W)Ff!pXGBxG;KMICR2rys+BzX>-0VrZbnuekW8;2Nku<64hM$jlsJwPp3 z1qm93tP!pl%_z7y@eDK*AY9_LLsSkPLxAqVbPTE9!RjgU48e5Is5xjMfEHh9vcz+# JWe)K+0sz+CNh|;W literal 0 HcmV?d00001 diff --git a/lib/matplotlib/mpl-data/images/help.svg b/lib/matplotlib/mpl-data/images/help.svg new file mode 100644 index 000000000000..484bdbcbf659 --- /dev/null +++ b/lib/matplotlib/mpl-data/images/help.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/mpl-data/images/help_large.png b/lib/matplotlib/mpl-data/images/help_large.png new file mode 100644 index 0000000000000000000000000000000000000000..3f3d4dfed7e99421bd024c14046bf4616b4ca2ff GIT binary patch literal 747 zcmVqZlEAow3ozPGS*Kh@=uh zt29YU!QR5c(o#^cu@D3i!6G7pMU;S|f`x@3Xc1C~VANnE8bvE}zs2r?guR>H+qXM8 z*dHDo`)=m{|CxC+vulzVWDLa?P!+9#*k}#JMr$B8S_84s8i^wG?Y0}H@YNgIJCvw{4NvH}_j zl94@6cqh8lSPhgAKTEP3g~V?H2e*v@l5O#R0pVHPDa}!%`28eBT~z!tV02p;0Coef zN{GKl)0eq`feQtNuLEqY{x&dHmCyZ^5;y`J2>j=Xq_ZAmb-dJ%1@eD@ zb6#Y182BB?zmc@&MdrSQB)v1UtH7b0bO*TZ$!BTd4J_*TF0_kelqYi1*?s?(8=v&002ovPDHLkV1l@aH3$Fz literal 0 HcmV?d00001 diff --git a/lib/matplotlib/mpl-data/images/help_large.ppm b/lib/matplotlib/mpl-data/images/help_large.ppm new file mode 100644 index 0000000000000000000000000000000000000000..4cf30807b0a14c3aabf7267488cc16e61c4d357e GIT binary patch literal 6925 zcmeHFTN1)R2=jYS;TfFP=`pvCDP6_sBpOxQ3{kz?Z}qycY>AQ;;9Q*SSLX^8c;}(E~Qn{w55mc zAeBbYU6&G~u7%KZU(k|9+*j9PLtR9yTX!6#5pfr75Td$78izq6sg8A!XoD6#RHShg zI;sX#5i0sC Date: Thu, 7 Sep 2017 14:25:40 -0400 Subject: [PATCH 2/6] more space for keys --- lib/matplotlib/backend_tools.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index b444dfbcd41d..4c60f72929c0 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -1037,19 +1037,19 @@ def enable(self, *args): table.edges = 'B' self.text_axes.add_table(table) chars_in_width = self._find_chars_in_width(table.FONTSIZE) - - table.auto_set_font_size(False) - col_chars_width = int(chars_in_width / 4) - 2 - content = self._get_content(col_chars_width, col_chars_width, - 2 * col_chars_width) + col_chars_width = int(chars_in_width / 6) + content = self._get_content(1 * col_chars_width - 2, + 2 * col_chars_width - 2, + 3 * col_chars_width - 2) for i, v in enumerate(content): h = v[0] table.add_cell(i, 0, text=v[1], width=1, height=h, loc='left', fontproperties='monospace') - table.add_cell(i, 1, text=v[2], width=1, height=h, loc='left', + table.add_cell(i, 1, text=v[2], width=2, height=h, loc='left', fontproperties='monospace') - table.add_cell(i, 2, text=v[3], width=2, height=h, loc='left', + table.add_cell(i, 2, text=v[3], width=3, height=h, loc='left', fontproperties='monospace') + table.auto_set_font_size(True) self.figure.canvas.draw_idle() def _find_chars_in_width(self, fontsize): From 2ce02b4c95efb73ec6f8cac1c5863a1a30fcbdce Mon Sep 17 00:00:00 2001 From: Federico Ariza Date: Thu, 7 Sep 2017 14:30:43 -0400 Subject: [PATCH 3/6] grammar/ortograph --- lib/matplotlib/backend_tools.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index 4c60f72929c0..6d3980838e1a 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -405,7 +405,7 @@ def trigger(self, sender, event, data=None): class ToolEnableAllNavigation(ToolBase): """Tool to enable all axes for toolmanager interaction""" - description = 'Enables all axes toolmanager' + description = 'Enable all axes toolmanager' default_keymap = rcParams['keymap.all_axes'] def trigger(self, sender, event, data=None): @@ -421,7 +421,7 @@ def trigger(self, sender, event, data=None): class ToolEnableNavigation(ToolBase): """Tool to enable a specific axes for toolmanager interaction""" - description = 'Enables one axes toolmanager' + description = 'Enable one axes toolmanager' default_keymap = (1, 2, 3, 4, 5, 6, 7, 8, 9) def trigger(self, sender, event, data=None): @@ -472,7 +472,7 @@ def _get_uniform_grid_state(ticks): class ToolGrid(_ToolGridBase): """Tool to toggle the major grids of the figure""" - description = 'Toogle major grids' + description = 'Toggle major grids' default_keymap = rcParams['keymap.grid'] def _get_next_grid_states(self, ax): @@ -493,7 +493,7 @@ def _get_next_grid_states(self, ax): class ToolMinorGrid(_ToolGridBase): """Tool to toggle the major and minor grids of the figure""" - description = 'Toogle major and minor grids' + description = 'Toggle major and minor grids' default_keymap = rcParams['keymap.grid_minor'] def _get_next_grid_states(self, ax): @@ -513,7 +513,7 @@ def _get_next_grid_states(self, ax): class ToolFullScreen(ToolToggleBase): """Tool to toggle full screen""" - description = 'Toogle Fullscreen mode' + description = 'Toggle fullscreen mode' default_keymap = rcParams['keymap.fullscreen'] def enable(self, event): @@ -543,7 +543,7 @@ def disable(self, event): class ToolYScale(AxisScaleBase): """Tool to toggle between linear and logarithmic scales on the Y axis""" - description = 'Toogle Scale Y axis' + description = 'Toggle scale Y axis' default_keymap = rcParams['keymap.yscale'] def set_scale(self, ax, scale): @@ -553,7 +553,7 @@ def set_scale(self, ax, scale): class ToolXScale(AxisScaleBase): """Tool to toggle between linear and logarithmic scales on the X axis""" - description = 'Toogle Scale X axis' + description = 'Toggle scale X axis' default_keymap = rcParams['keymap.xscale'] def set_scale(self, ax, scale): From a06a80ba6ce7be1e2f956956742ef9de047f25f3 Mon Sep 17 00:00:00 2001 From: Federico Ariza Date: Thu, 7 Sep 2017 18:36:19 -0400 Subject: [PATCH 4/6] pep8 imports and unique axes with custom label --- lib/matplotlib/backend_tools.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index 6d3980838e1a..00d45f8ae2e4 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -14,13 +14,12 @@ import time import warnings from weakref import WeakKeyDictionary - +import textwrap import numpy as np from matplotlib import rcParams from matplotlib._pylab_helpers import Gcf from matplotlib.table import Table -import textwrap import matplotlib.cbook as cbook @@ -1032,7 +1031,10 @@ def __init__(self, *args): self.text_axes = None def enable(self, *args): - self.text_axes = self.figure.add_axes((0, 0, 1, 1)) + # Using custom axes label to prevent reuse of old axes + # https://github.com/matplotlib/matplotlib/issues/9024 + self.text_axes = self.figure.add_axes((0, 0, 1, 1), + label='help_tool_axes') table = Table(self.text_axes, bbox=[0, 0, 1, 1]) table.edges = 'B' self.text_axes.add_table(table) From 54cf09f8ff64aa58f1f835122763e9d4293383a5 Mon Sep 17 00:00:00 2001 From: Federico Ariza Date: Thu, 12 Apr 2018 16:06:12 -0400 Subject: [PATCH 5/6] add help entry to matplotlibrc.template --- matplotlibrc.template | 1 + 1 file changed, 1 insertion(+) diff --git a/matplotlibrc.template b/matplotlibrc.template index cf4e0803106b..a3416144f0f0 100644 --- a/matplotlibrc.template +++ b/matplotlibrc.template @@ -583,6 +583,7 @@ backend : $TEMPLATE_BACKEND #keymap.pan : p ## pan mnemonic #keymap.zoom : o ## zoom mnemonic #keymap.save : s, ctrl+s ## saving current figure +#keymap.help : f1 ## display help about active tools #keymap.quit : ctrl+w, cmd+w, q ## close the current figure #keymap.quit_all : W, cmd+W, Q ## close all figures #keymap.grid : g ## switching on/off major grids in current axes From b89a904d2e12862a6e8cad8e18fbb2ee261402de Mon Sep 17 00:00:00 2001 From: Federico Ariza Date: Thu, 12 Apr 2018 17:00:19 -0400 Subject: [PATCH 6/6] reusing the help tool axes --- lib/matplotlib/backend_tools.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index 00d45f8ae2e4..c3eccabbf66d 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -1033,8 +1033,12 @@ def __init__(self, *args): def enable(self, *args): # Using custom axes label to prevent reuse of old axes # https://github.com/matplotlib/matplotlib/issues/9024 - self.text_axes = self.figure.add_axes((0, 0, 1, 1), - label='help_tool_axes') + if not self.text_axes: + self.text_axes = self.figure.add_axes((0, 0, 1, 1), + label='help_tool_axes') + self.text_axes.set_visible(True) + self.text_axes.clear() + table = Table(self.text_axes, bbox=[0, 0, 1, 1]) table.edges = 'B' self.text_axes.add_table(table) @@ -1063,7 +1067,7 @@ def _find_chars_in_width(self, fontsize): return figwidth / charwidth def disable(self, *args): - self.text_axes.remove() + self.text_axes.set_visible(False) self.figure.canvas.draw_idle() def _get_content(self, w0, w1, w2): pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy