|
From: Eric F. <ef...@ha...> - 2012-08-30 00:04:13
|
On 2012/08/27 5:10 AM, Francesco Montesano wrote: > Dear matplotlibers, > > I encountered a bug (?) in fill_between when using logarithmic scales and > the last part of y and yerr arrays as set to zero: a diagonal stripe going from > the rightmost non zero value to the first value is drawn. > It's visible in the right panel of the attached figure, while is not > present if the plot is linear (left panel). > If xaxis is log and yaxis is linear the plot is correctly drawn. > > I'm using mpl.__version__ = '1.1.1rc' under Kubuntu 12.04 with Python 2.7.3 > > The plot has been created with the script below. > > Is this a bug or am I missing something? I don't think it is exactly a bug, but I don't know why the fill region is appearing as it does. The underlying problem is that fill_between is doing what it is told to do without knowing that it is going to be plotted on a log axis. A good workaround is to change your call to fill_between to look like this: positive = y - yerr > 0 ax2.fill_between( x,y-yerr,y+yerr, where=positive, color='b', alpha=0.4) Alternatively, you could use np.clip to put a floor under y - yerr and y + yerr. Eric > > Cheers > Francesco > > > ##### error_fill_between.py ###### > import matplotlib.pyplot as plt > import numpy as np > > #values to plot > x = np.linspace( 1, 10, num=100 ) > y = np.exp( -x**2 ) > y[50:] = 0 > yerr = y* np.random.rand(100) > > #figure > fig = plt.figure() > > ax1 = fig.add_subplot(121) #first axes: linear > ax1.errorbar( x,y,yerr, c='r' ) > ax1.fill_between( x,y-yerr,y+yerr, color='b', alpha=0.4 ) > > ax2 = fig.add_subplot(122) #second axes: logarithmic > ax2.errorbar( x,y,yerr, c='r' ) > ax2.fill_between( x,y-yerr,y+yerr, color='b', alpha=0.4 ) > ax2.set_xscale( "log" ) > ax2.set_yscale( "log" ) > > plt.show() > ###### end script ######### > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > > > > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |