Pyplot colorbar offsets subplot size8/27/2023 ![]() ![]() set_major_locator ( MaxNLocator ( integer = True )) ax. set_major_formatter ( FuncFormatter ( format_fnx )) ax. arange ( len ( Y ) + 1 ) - 0.5, C, cmap = mycmap, ** kwargs ) ax = plt. size : return str ( Y ) else : return '' r = plt. shape ( C )) ) def format_fnx ( val, pos ): k = int ( round ( val )) if k >= 0 and k = 0 and k < Y. shape ( Y )) + ', it should be ' + str ( np. shape ( C )) + ' is incompatible with the dimension of Y = ' + str ( np. ![]() shape ( Y ): raise TypeError ( 'Dimension of C (y,x)=' + str ( np. shape ( X )) + ', it should be ' + str ( np. shape ( C )) + ' is incompatible with the dimension of X = ' + str ( np. shape ( X ): raise TypeError ( 'Dimension of C (y,x)=' + str ( np. shape ( Y )) != 1 : raise TypeError ( 'Y must be one-dimensional but is of shape ' + str ( np. shape ( X )) != 1 : raise TypeError ( 'X must be one-dimensional but is of shape ' + str ( np. shape ( args )) C = args elif len ( args ) = 3 : X = args Y = args C = args else : raise TypeError ( 'Incompatible X, Y or C inputs to %s see help( %s )' % ( funcname, funcname )) # more error checking: if len ( np. pop ( 'cmap', None ) if mycmap is None : mycmap = copy. Example: Plot a 16x16 bin matrix:: import numpy as np import matplotlib.pyplot as plt import as icaplt C=np.arange(128).reshape((16,8)) # (y,x) otbinnedmatrix(np.arange(8),np.arange(16), C) plt.title('A binned 8x16 matrix') Or also shorter:: plotbinnedmatrix(C) ''' # make my default colormap # cmap = plt.get_cmap('viridis') # cmap = plt.get_cmap('jet') # cmap = et mycmap = kwargs. The shape of C must be (Y,X), otherwise an error is generated. ![]() Call signatures:: plotbinnedmatrix(C) plotbinnedmatrix(X, Y, C) plotbinnedmatrix(C, **kwargs) plotbinnedmatrix(X, Y, C, **kwargs) If X and Y are given, then the values in them are used as axis labels. In addition to pcolormesh(), this function makes sure the lables are centered on each bin on both axes and that all bins are plotted, including the last one. It takes the similar parameters as pcolormesh(). def plotbinnedmatrix ( * args, ** kwargs ): r ''' Plots a color matrix (also known as a quadrilateral mesh) using (). replace ( " ", "" ) if font = 'times' : # Times font = $' %expo # Turn off the offset text that's calculated automatically # ax_visible(False) # Add in a text box at the top of the y axis # ax.text(x_pos, y_pos, offset_text, transform=ax.transAxes, # horizontalalignment=horizontalalignment, # verticalalignment=verticalalignment) # return ax rc ( 'text', usetex = True ) font = font. Parameters: font (string): "Helvetica" "Times" "Computer Modern" unicode (boolean): Use unicode. Revert all changes by calling rcdefault() from matplotlib. Calling this makes sure there will be identical looking fonts independent of the output device and wether latex is used or not. Def setfont ( font = "Helvetica", unicode = True ): r """ Set Matplotlibs rcParams to use LaTeX for font rendering. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |