Re: [Matplotlib-users] histogram plots color range
nahren manuel wrote: > > Hello , > I have a two dimensional array, 40X20(rowsXcolumns). Each of the 40 rows > themselves hold values of the bins of a distribution (which is not always > normal, can expect a bimodal curve as well) > > It is little difficult to explain to I actually created a sample figure: > > http://www.flickr.com/photos/nahrenmascarenhas/6771369071/in/photostream > > Any help or trick will be very useful > loads of thanks > > nahren > I took some of the code that I use regularly and came up with this minimal example of fitting data very similar to the figure you showed above. I hope the explanations in the code are clear enough. https://sites.google.com/site/theodoregoetz/notes/fittingaprofilein2dhistogramdata link to my website with code example Here is the code and the output figure. Hope this helps someone! Johann. http://old.nabble.com/file/p33231288/y_profile.py y_profile.py http://old.nabble.com/file/p33231288/y_profile.png -- View this message in context: http://old.nabble.com/histogram-plots-color-range-tp33215265p33231288.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to shift colormap?
I have this script that uses the matplotlib Slider object to control the colormap of a histogram. This could be very close to what you want. Here is the script: ### begin colormap_slider.py # import math, copy import numpy from matplotlib import pyplot, colors, cm from matplotlib.widgets import Slider def cmap_powerlaw_adjust(cmap, a): ''' returns a new colormap based on the one given but adjusted via power-law: newcmap = oldcmap**a ''' if a < 0.: return cmap cdict = copy.copy(cmap._segmentdata) fn = lambda x : (x[0]**a, x[1], x[2]) for key in ('red','green','blue'): cdict[key] = map(fn, cdict[key]) cdict[key].sort() assert (cdict[key][0]<0 or cdict[key][-1]>1), \ "Resulting indices extend out of the [0, 1] segment." return colors.LinearSegmentedColormap('colormap',cdict,1024) def cmap_center_adjust(cmap, center_ratio): ''' returns a new colormap based on the one given but adjusted so that the old center point higher (>0.5) or lower (<0.5) ''' if not (0. < center_ratio) & (center_ratio < 1.): return cmap a = math.log(center_ratio) / math.log(0.5) return cmap_powerlaw_adjust(cmap, a) def cmap_center_point_adjust(cmap, range, center): ''' converts center to a ratio between 0 and 1 of the range given and calls cmap_center_adjust(). returns a new adjusted colormap accordingly ''' if not ((range[0] < center) and (center < range[1])): return cmap return cmap_center_adjust(cmap, abs(center - range[0]) / abs(range[1] - range[0])) if __name__ == '__main__': ### create some 2D histogram-type data def func3(x,y): return (1- x/2 + x**5 + y**3)*numpy.exp(-x**2-y**2) x = numpy.linspace(-3.0, 3.0, 60) y = numpy.linspace(-3.0, 3.0, 60) X,Y = numpy.meshgrid(x, y) Z = func3(X, Y) extent = [x[0],x[-1],y[0],y[-1]] plotkwargs = { 'extent' : extent, 'origin' : 'lower', 'interpolation' : 'nearest', 'aspect' : 'auto'} ### interactively adjustable with a slider fig = pyplot.figure(figsize=(6,4)) fig.subplots_adjust(top=0.8) ax = fig.add_subplot(1,1,1) cmap = cm.seismic plt = ax.imshow(Z, cmap=cmap, **plotkwargs) cb = fig.colorbar(plt, ax=ax) axcmap = fig.add_axes([0.1, 0.85, 0.8, 0.05], axisbg='white') scmap = Slider(axcmap, '', 0.0, 1.0, valinit=0.5) def update(val): cmapcenter = scmap.val plt.set_cmap(cmap_center_adjust(cmap, cmapcenter)) scmap.on_changed(update) pyplot.show() ### end colormap_slider.py ### -- View this message in context: http://old.nabble.com/How-to-shift-colormap--tp32792283p32827012.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- RSA(R) Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] colorbar and scilimits
Is there a way to set the style and scilimits to the colorbar axes? All my attempts failed. For example, run the following script, I get the error shown below: ### begin example script import numpy from matplotlib import pyplot n = 500 x = numpy.random.standard_normal(n) y = 2.0 + 3.0 * x + 4.0 * numpy.random.standard_normal(n) xmin = x.min() xmax = x.max() ymin = y.min() ymax = y.max() hist, edges = numpy.histogramdd([y,x], bins=[25,25], range=[[ymin,ymax], [xmin,xmax]]) extent = [xmin, xmax, ymin, ymax] fig = pyplot.figure() ax = fig.add_subplot(1,1,1) plt = ax.imshow(hist, extent = extent, origin = 'lower', interpolation = 'nearest', aspect = 'auto') cb = fig.colorbar(plt, ax=ax) # This causes an AttributeError exception cb.ax.ticklabel_format(style='sci', scilimits=(0,4)) pyplot.show() ### end example script > python cb_scilim_test.py Traceback (most recent call last): File "cb_scilim_test.py", line 25, in cb.ax.ticklabel_format(style='sci', scilimits=(0,4)) File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 2117, in ticklabel_format "This method only works with the ScalarFormatter.") AttributeError: This method only works with the ScalarFormatter. -- View this message in context: http://old.nabble.com/colorbar-and-scilimits-tp31201133p31201133.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] 1D and 2D histograms using numpy and matplotlib
There have been a lot of messages lately about histograms in general and I though it was about time I share a bit of code I am using to handle them. I have created a Histogram class that inherits directly from the numpy.ndarray object. I then have a plothist() method which creates the plot on a canvas. For 1D histograms, I create the PathPatch (Polygon) fom a series of points. This is so that the histogram can be a single patch with a facecolor and an edgecolor, though I usually have the edgecolor set to None. For 2D histograms I use imshow() with interpolation='nearest'. This gives rectangular bins which I prefer (over the hexbin) since typically, the resolution of the x and y axes are different for me. I'm relatively new to python so the code may be improved, but so far, it has worked quite nicely for me. Hopefully it will work for someone else! And of course, if anyone has any comments or suggestions, please let me know! All definitions are in histogram.py. Put the test.py file in the same directory and run test.py to make sure everything works. http://old.nabble.com/file/p30998708/histogram.py histogram.py http://old.nabble.com/file/p30998708/test.py test.py Running test.py should give you several histogram figures including these: http://old.nabble.com/file/p30998708/1dhist_color.png http://old.nabble.com/file/p30998708/2dhist_zeroed_colorbar.png -- View this message in context: http://old.nabble.com/1D-and-2D-histograms-using-numpy-and-matplotlib-tp30998708p30998708.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] zoomed copy of axis for grid of subplots
Thanks guys! This is exactly what I was looking for. The axes_grid1 toolkit works like a charm. I have attached a revised version of the example I had before with a few minor modifications and some descriptive text at the top. Is there a standard way for non-developers (i.e. users) to contribute examples like these? Thanks again! http://old.nabble.com/file/p30807907/grid_histogram.py grid_histogram.py http://old.nabble.com/file/p30807907/grid_histogram.png -- View this message in context: http://old.nabble.com/zoomed-copy-of-axis-for-grid-of-subplots-tp30748088p30807907.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] zoomed copy of axis for grid of subplots
Hello, A common task I have is to histogram one variable of a multidimensional dataset as a function of two (or more) variables. I have attached an example which shows exactly what I would like to do. The problem I would like to solve is the zoomed in x-axis which is the last part of the script attached. I start by copying one of the subplots with Axes.twiny() and proceed to adjust it and label it. The results are quite nice but as soon as I start adjusting the plotted window or any of the subplot spacing parameters, this "copy of an axis" does not transform properly. Could anyone make a suggestion as to which transformations I should use to shift and zoom the new axes? Or perhaps there is a better method for drawing a zoomed in version of an axis? I would like to submit this to the examples/gallery page but feel that these details need to be addressed, and I am not sure I know how to fix them. Hopefully, I have commented this example enough that someone could follow what I am doing. Thank you, Johann http://old.nabble.com/file/p30748088/grid_plot.png http://old.nabble.com/file/p30748088/grid_plot.py grid_plot.py -- View this message in context: http://old.nabble.com/zoomed-copy-of-axis-for-grid-of-subplots-tp30748088p30748088.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users