Repository navigation
Closed
Milestone
Description
plt.clf()
fig, ax = plt.subplots(1,2, sharey=True)
plt.setp(ax.flat, aspect=1.0, adjustable='box-forced')
#fig.set_size_inches(16,8)
sns.despine(fig=fig)
#scale = 'logit'
scale = None
plot.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)
plot.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)
plot.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)
plot.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)
for i in range(2):
ax[i].set_yscale("logit", p_min=1e-4)
ax[i].legend(bbox_to_anchor=(0., 1.02, 1., .102), borderaxespad=0., frameon=True, fancybox=True)
plt.savefig("temp.pdf",bbox_inches='tight')When running the above code I am getting the following error:
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-75-76bd951dfd46> in <module>()
19
20
---> 21 plt.savefig("Novelty_year_dist_logit.pdf",bbox_inches='tight')
22 plt.savefig("Novelty_year_dist_logit.eps",bbox_inches='tight')
/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in savefig(*args, **kwargs)
575 def savefig(*args, **kwargs):
576 fig = gcf()
--> 577 res = fig.savefig(*args, **kwargs)
578 draw() # need this if 'transparent=True' to reset colors
579 return res
/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in savefig(self, *args, **kwargs)
1474 self.set_frameon(frameon)
1475
-> 1476 self.canvas.print_figure(*args, **kwargs)
1477
1478 if frameon:
/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2156 orientation=orientation,
2157 dryrun=True,
-> 2158 **kwargs)
2159 renderer = self.figure._cachedRenderer
2160 bbox_inches = self.figure.get_tightbbox(renderer)
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.pyc in print_pdf(self, filename, **kwargs)
2483 RendererPdf(file, image_dpi),
2484 bbox_inches_restore=_bbox_inches_restore)
-> 2485 self.figure.draw(renderer)
2486 renderer.finalize()
2487 finally:
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/usr/local/lib/python2.7/dist-packages/matplotlib/figure.pyc in draw(self, renderer)
1083 dsu.sort(key=itemgetter(0))
1084 for zorder, a, func, args in dsu:
-> 1085 func(*args)
1086
1087 renderer.close_group('figure')
/usr/local/lib/python2.7/dist-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
2004 self.apply_aspect(pos)
2005 else:
-> 2006 self.apply_aspect()
2007
2008 artists = []
/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in apply_aspect(self, position)
1191 fig_aspect = figH / figW
1192 if self._adjustable in ['box', 'box-forced']:
-> 1193 if aspect_scale_mode == "log":
1194 box_aspect = A * self.get_data_ratio_log()
1195 else:
UnboundLocalError: local variable 'aspect_scale_mode' referenced before assignment
However, running the example explained in http://stackoverflow.com/a/13663328/1650159 doesn't give this error.
Additional Info:
def plot_year_dist(df,col='',col_label="",thresh=0,file_prefix='',outFolder=DEFAULT_OUTPUT,\
ax=None,color=sns.xkcd_rgb['black'],label='',scale=None,**kwargs):
saveFig = False
if ax is None:
plt.clf()
ax = plt.gca()
saveFig = True
filename = file_prefix+col+"_year_dist.png"
df_g = df[[col,'Year']].groupby('Year').count()
df_g["filtered"] = df[[col,"Year"]][df[col] <= thresh].groupby("Year").count()
df_g["prop"] = df_g["filtered"]/df_g[col]
#print df_g.index
#print df_g
x = df_g.index.values
y = df_g["prop"].values
if scale == 'logit':
y = np.log10(y/(1.0-y))
ax.plot(x,y, linestyle='-',markersize=3.0,color=color,label=label,**kwargs)
print "Finished generating histogram"
ax.set_xlabel(col_label)
ax.set_ylabel("Proportion (<= %s)" % thresh)
if scale == 'logit':
ax.set_ylabel("$log_{10}(p/1-p)$ [$p = P(X<= %s)$]" % thresh)
if saveFig:
plt.savefig(outFolder+"/"+filename)
print "Plot saved in %s." % (filename)Metadata
Metadata
Assignees
Labels
No labels
Activity
WeatherGod commentedon Aug 11, 2015
Looks like this piece of code is the problem part:
It has two branches where
aspect_scale_modeis left undefined. Probablyhave it set to None or something like that. I'll put together a PR.
On Tue, Aug 11, 2015 at 6:31 AM, Shubhanshu Mishra <notifications@github.com
WeatherGod commentedon Aug 11, 2015
I just tried making a test based off of your example, but I don't know 1)
the scale of your data and 2) the p_min argument doesn't seem to be valid.
I am not sure how that works for you. Could you try making a more
simplified version of your script that demonstrates the problem and can
easily be made into a test.
On Tue, Aug 11, 2015 at 8:56 AM, Benjamin Root ben.root@ou.edu wrote:
napsternxg commentedon Aug 11, 2015
Hi @WeatherGod thanks for looking into this.
The code is supposed to ensure that each subplot is square in shape.
Here is another set of code which I am running before running the above lines of code:
p_minargument is for controlling the parameters of the logit scale.WeatherGod commentedon Aug 11, 2015
Ah, that would explain why the logit scale wasn't working (matplotlib has
its own logit scale available).
This example, though isn't a SSCCE: http://sscce.org/
It isn't short, nor is it self-contained (I don't have the data, nor do I
want the data). The example doesn't need the extra bells and whistles, and
it can have fake data generated using np.logspace(). The x-data doesn't
need to be dates, either, for the purposes of the demonstration.
On Tue, Aug 11, 2015 at 12:43 PM, Shubhanshu Mishra <
notifications@github.com> wrote:
napsternxg commentedon Aug 11, 2015
I am using version 1.4.3 in which the logit scale is not present. Hence I had to write this class.
WeatherGod commentedon Aug 11, 2015
Ah, I was testing with the master branch, which has it, but is a little bit
different. In any case, I still need an SSCCE, even if it doesn't work for
you. I have no clue what fake data to use in my test. This is what I have
so far:
master...WeatherGod:fix_4900,
but the result looks terrible.
On Tue, Aug 11, 2015 at 1:32 PM, Shubhanshu Mishra <notifications@github.com
napsternxg commentedon Aug 11, 2015
This is an SSCE using matplotlib version 1.4.3
Running the above code gives the following error:
duncanmmacleod commentedon Oct 4, 2017
This still seems to be an issue using matplotlib 2.0.2:
Here the traceback is:
duncanmmacleod commentedon Oct 4, 2017
It seems to me the problem is that the scales are referred by name, rather than by type, e.g.
rather than
I'm not familiar with why the scales are referred to absolutely, rather than relatively, can someone comment?
tacaswell commentedon Oct 4, 2017
@phobson probably understands this best right now.
tacaswell commentedon Oct 4, 2017
The
git blameon that function is all pretty old (2007 - 2010) so the original motivation may be lost to the sands of time.phobson commentedon Oct 9, 2017
@tacaswell getting back from vacation, will take a look at this tomorrow,
jbndlr commentedon Aug 23, 2018
Any news on this? Running into the same error when creating custom scales and trying to save the resulting figure.
anntzer commentedon Aug 23, 2018
A simple repro is
Looks like a correct fix should "simply" be along the lines of
and deprecate get_data_ratio/get_data_ratio_log (the fix just applies the actual scale transform to the data limits and computes the ratio from that). Except that this will break custom projections that override get_data_ratio (which is explicitly defined as a overridable method), so we need to figure out how to handle that (perhaps change the behavior of the default get_data_ratio instead to make it do the proper calculation).
Edit (note to self): @efiring suggested we could put this behavior into get_data_ratio so that overriding get_data_ratio still works.
zc62 commentedon May 3, 2019
@phobson
Ran into this problem when trying to set equal axis for a symlog-symlog plot. The error occurs at
Any chance for this to get some attention?
It looks like only
linearandlogscales are supported. Using other scales such assymlogandlogitwill trigger the bug. (Actually this is an unimplemented feature.)EDIT: nvm, there is an issue for the feature now.