{"action":"created","issue":{"url":"https://api.github.com/repos/matplotlib/matplotlib/issues/4900","labels_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/4900/labels{/name}","comments_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/4900/comments","events_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/4900/events","html_url":"https://github.com/matplotlib/matplotlib/issues/4900","id":100283033,"number":4900,"title":"UnboundLocalError: local variable 'aspect_scale_mode' referenced before assignment","user":{"login":"napsternxg","id":112678,"avatar_url":"https://avatars.githubusercontent.com/u/112678?v=3","gravatar_id":"","url":"https://api.github.com/users/napsternxg","html_url":"https://github.com/napsternxg","followers_url":"https://api.github.com/users/napsternxg/followers","following_url":"https://api.github.com/users/napsternxg/following{/other_user}","gists_url":"https://api.github.com/users/napsternxg/gists{/gist_id}","starred_url":"https://api.github.com/users/napsternxg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/napsternxg/subscriptions","organizations_url":"https://api.github.com/users/napsternxg/orgs","repos_url":"https://api.github.com/users/napsternxg/repos","events_url":"https://api.github.com/users/napsternxg/events{/privacy}","received_events_url":"https://api.github.com/users/napsternxg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-08-11T10:31:04Z","updated_at":"2015-08-11T17:32:50Z","closed_at":null,"body":"```python\r\nplt.clf()\r\nfig, ax = plt.subplots(1,2, sharey=True)\r\nplt.setp(ax.flat, aspect=1.0, adjustable='box-forced')\r\n#fig.set_size_inches(16,8)\r\nsns.despine(fig=fig)\r\n#scale = 'logit'\r\nscale = None\r\nplot.plot_year_dist(df_mesh[(df_mesh['Year'] >= min_y) & (df_mesh['Year'] <= 2009)],col='min_VolFirstP',col_label=\"Year\",thresh=10,file_prefix='individual_', ax=ax[0],color=sns.xkcd_rgb['black'],label='Individual Volume [%s-2009]' % min_y,marker=\"o\", scale = scale)\r\nplot.plot_year_dist(df[(df['Year'] >= min_y) & (df['Year'] <= 2009)],col='min_VolFirstP',col_label=\"Year\",thresh=10,file_prefix='pair_', ax=ax[0],color=sns.xkcd_rgb['red'],label='Pair Volume [%s-2009]' % min_y, marker=\"s\", scale = scale)\r\n\r\n\r\nplot.plot_year_dist(df_mesh[(df_mesh['Year'] >= min_y) & (df_mesh['Year'] <= 2009)],col='min_TFirstP',col_label=\"Years\",thresh=3,file_prefix='individual_', ax=ax[1],color=sns.xkcd_rgb['black'],label='Individual Time [%s-2009]' % min_y,marker=\"o\", scale = scale)\r\nplot.plot_year_dist(df[(df['Year'] >= min_y) & (df['Year'] <= 2009)],col='min_TFirstP',col_label=\"Years\",thresh=3,file_prefix='pair_', ax=ax[1],color=sns.xkcd_rgb['red'],label='Pair Time [%s-2009]' % min_y,marker=\"s\", scale = scale)\r\n\r\nfor i in range(2):\r\n\tax[i].set_yscale(\"logit\", p_min=1e-4)\r\n\tax[i].legend(bbox_to_anchor=(0., 1.02, 1., .102), borderaxespad=0., frameon=True, fancybox=True)\r\n\r\nplt.savefig(\"temp.pdf\",bbox_inches='tight')\r\n```\r\n\r\nWhen running the above code I am getting the following error:\r\n\r\n```\r\n---------------------------------------------------------------------------\r\nUnboundLocalError                         Traceback (most recent call last)\r\n<ipython-input-75-76bd951dfd46> in <module>()\r\n     19 \r\n     20 \r\n---> 21 plt.savefig(\"Novelty_year_dist_logit.pdf\",bbox_inches='tight')\r\n     22 plt.savefig(\"Novelty_year_dist_logit.eps\",bbox_inches='tight')\r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in savefig(*args, **kwargs)\r\n    575 def savefig(*args, **kwargs):\r\n    576     fig = gcf()\r\n--> 577     res = fig.savefig(*args, **kwargs)\r\n    578     draw()   # need this if 'transparent=True' to reset colors\r\n    579     return res\r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in savefig(self, *args, **kwargs)\r\n   1474             self.set_frameon(frameon)\r\n   1475 \r\n-> 1476         self.canvas.print_figure(*args, **kwargs)\r\n   1477 \r\n   1478         if frameon:\r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)\r\n   2156                     orientation=orientation,\r\n   2157                     dryrun=True,\r\n-> 2158                     **kwargs)\r\n   2159                 renderer = self.figure._cachedRenderer\r\n   2160                 bbox_inches = self.figure.get_tightbbox(renderer)\r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.pyc in print_pdf(self, filename, **kwargs)\r\n   2483                 RendererPdf(file, image_dpi),\r\n   2484                 bbox_inches_restore=_bbox_inches_restore)\r\n-> 2485             self.figure.draw(renderer)\r\n   2486             renderer.finalize()\r\n   2487         finally:\r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)\r\n     57     def draw_wrapper(artist, renderer, *args, **kwargs):\r\n     58         before(artist, renderer)\r\n---> 59         draw(artist, renderer, *args, **kwargs)\r\n     60         after(artist, renderer)\r\n     61 \r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in draw(self, renderer)\r\n   1083         dsu.sort(key=itemgetter(0))\r\n   1084         for zorder, a, func, args in dsu:\r\n-> 1085             func(*args)\r\n   1086 \r\n   1087         renderer.close_group('figure')\r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)\r\n     57     def draw_wrapper(artist, renderer, *args, **kwargs):\r\n     58         before(artist, renderer)\r\n---> 59         draw(artist, renderer, *args, **kwargs)\r\n     60         after(artist, renderer)\r\n     61 \r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)\r\n   2004             self.apply_aspect(pos)\r\n   2005         else:\r\n-> 2006             self.apply_aspect()\r\n   2007 \r\n   2008         artists = []\r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in apply_aspect(self, position)\r\n   1191         fig_aspect = figH / figW\r\n   1192         if self._adjustable in ['box', 'box-forced']:\r\n-> 1193             if aspect_scale_mode == \"log\":\r\n   1194                 box_aspect = A * self.get_data_ratio_log()\r\n   1195             else:\r\n\r\nUnboundLocalError: local variable 'aspect_scale_mode' referenced before assignment\r\n```\r\n\r\nHowever, running the example explained in http://stackoverflow.com/a/13663328/1650159 doesn't give this error. \r\n\r\nAdditional Info:\r\n```python\r\ndef plot_year_dist(df,col='',col_label=\"\",thresh=0,file_prefix='',outFolder=DEFAULT_OUTPUT,\\\r\n    ax=None,color=sns.xkcd_rgb['black'],label='',scale=None,**kwargs):\r\n  saveFig = False\r\n  if ax is None:\r\n    plt.clf()\r\n    ax = plt.gca()\r\n    saveFig = True\r\n  filename = file_prefix+col+\"_year_dist.png\"\r\n  df_g = df[[col,'Year']].groupby('Year').count()\r\n  df_g[\"filtered\"] = df[[col,\"Year\"]][df[col] <= thresh].groupby(\"Year\").count()\r\n  df_g[\"prop\"] = df_g[\"filtered\"]/df_g[col]\r\n  #print df_g.index\r\n  #print df_g\r\n  x = df_g.index.values\r\n  y = df_g[\"prop\"].values\r\n  if scale == 'logit':\r\n    y = np.log10(y/(1.0-y))\r\n\r\n  ax.plot(x,y, linestyle='-',markersize=3.0,color=color,label=label,**kwargs)\r\n\r\n  print \"Finished generating histogram\"\r\n  ax.set_xlabel(col_label)\r\n  ax.set_ylabel(\"Proportion (<= %s)\" % thresh)\r\n  if scale == 'logit':\r\n    ax.set_ylabel(\"$log_{10}(p/1-p)$ [$p = P(X<= %s)$]\" % thresh)\r\n  if saveFig:\r\n    plt.savefig(outFolder+\"/\"+filename)\r\n  print \"Plot saved in %s.\" % (filename)\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/matplotlib/matplotlib/issues/comments/129981032","html_url":"https://github.com/matplotlib/matplotlib/issues/4900#issuecomment-129981032","issue_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/4900","id":129981032,"user":{"login":"napsternxg","id":112678,"avatar_url":"https://avatars.githubusercontent.com/u/112678?v=3","gravatar_id":"","url":"https://api.github.com/users/napsternxg","html_url":"https://github.com/napsternxg","followers_url":"https://api.github.com/users/napsternxg/followers","following_url":"https://api.github.com/users/napsternxg/following{/other_user}","gists_url":"https://api.github.com/users/napsternxg/gists{/gist_id}","starred_url":"https://api.github.com/users/napsternxg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/napsternxg/subscriptions","organizations_url":"https://api.github.com/users/napsternxg/orgs","repos_url":"https://api.github.com/users/napsternxg/repos","events_url":"https://api.github.com/users/napsternxg/events{/privacy}","received_events_url":"https://api.github.com/users/napsternxg/received_events","type":"User","site_admin":false},"created_at":"2015-08-11T17:32:50Z","updated_at":"2015-08-11T17:32:50Z","body":"I am using version 1.4.3 in which the logit scale is not present. Hence I had to write this class. \r\n\r\n```python\r\n>>> plt.yscale(\"logit\")\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-4-7096907d257b> in <module>()\r\n----> 1 plt.yscale(\"logit\")\r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in yscale(*args, **kwargs)\r\n   1558     \"\"\"\r\n   1559     ax = gca()\r\n-> 1560     ax.set_yscale(*args, **kwargs)\r\n   1561     draw_if_interactive()\r\n   1562 \r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in set_yscale(self, value, **kwargs)\r\n   2852         if value.lower() == 'log' and 'nonposy' not in kwargs.keys():\r\n   2853             kwargs['nonposy'] = 'clip'\r\n-> 2854         self.yaxis._set_scale(value, **kwargs)\r\n   2855         self.autoscale_view(scalex=False)\r\n   2856         self._update_transScale()\r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/axis.pyc in _set_scale(self, value, **kwargs)\r\n    703 \r\n    704     def _set_scale(self, value, **kwargs):\r\n--> 705         self._scale = mscale.scale_factory(value, self, **kwargs)\r\n    706         self._scale.set_default_locators_and_formatters(self)\r\n    707 \r\n\r\n/usr/local/lib/python2.7/dist-packages/matplotlib/scale.pyc in scale_factory(scale, axis, **kwargs)\r\n    503 \r\n    504     if scale not in _scale_mapping:\r\n--> 505         raise ValueError(\"Unknown scale type '%s'\" % scale)\r\n    506 \r\n    507     return _scale_mapping[scale](axis, **kwargs)\r\n\r\nValueError: Unknown scale type 'logit'\r\n\r\n\r\n>>> matplotlib.__version__\r\n'1.4.3'\r\n```"}}