# For setting parameters, we will need to use matplotlib (mpl) directly import matplotlib as mpl # This is the usual invocation of pyplot import matplotlib.pyplot as plt import numpy as np import pandas as pd # Set the random seed for consistency np.random.seed(12) # I happen to know that there are 7 default colors in matplotlib for i in range(7): plt.plot(np.random.randn(1000).cumsum()) ! sudo easy_install brewer2mpl Searching for brewer2mpl Reading http://pypi.python.org/simple/brewer2mpl/ Reading https://github.com/jiffyclub/brewer2mpl/wiki Best match: brewer2mpl 1.3.1 Downloading http://pypi.python.org/packages/source/b/brewer2mpl/brewer2mpl-1.3.1.zip#md5=ae1e2cfc57e7e022e0208e2b5a994292 Processing brewer2mpl-1.3.1.zip Writing /tmp/easy_install-9BiZaj/brewer2mpl-1.3.1/setup.cfg Running brewer2mpl-1.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-9BiZaj/brewer2mpl-1.3.1/egg-dist-tmp-UKWbyr zip_safe flag not set; analyzing archive contents... brewer2mpl.brewer2mpl: module references __file__ Adding brewer2mpl 1.3.1 to easy-install.pth file Installed /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/brewer2mpl-1.3.1-py2.7.egg Processing dependencies for brewer2mpl Finished processing dependencies for brewer2mpl ! cat ~/.matplotlibrc | grep color_cycle import brewer2mpl # brewer2mpl.get_map args: set name set type number of colors bmap = brewer2mpl.get_map('Set2', 'qualitative', 7) colors = bmap.mpl_colors print colors # Set the random seed for consistency np.random.seed(12) # Change the default colors mpl.rcParams['axes.color_cycle'] = colors # I happen to know that there are 7 default colors in matplotlib for i in range(7): plt.plot(np.random.randn(1000).cumsum()) # Set the random seed for consistency np.random.seed(12) # Change the default colors #mpl.rcParams['axes.color_cycle'] = colors = brewer2mpl.get_map('Set2', 'qualitative', 7).mpl_colors #matplotlib.image.cmap = brewer2mpl.get_map('Set2', 'qualitative', 7).mpl_colormap # I happen to know that there are 7 default colors in matplotlib for i, color in enumerate(colors): plt.scatter(np.random.randn(1000), np.random.randn(1000), color=color) # Set the random seed for consistency np.random.seed(12) # Change the default colors #mpl.rcParams['axes.color_cycle'] = colors = brewer2mpl.get_map('Set2', 'qualitative', 7).mpl_colors #matplotlib.image.cmap = brewer2mpl.get_map('Set2', 'qualitative', 7).mpl_colormap # I happen to know that there are 7 default colors in matplotlib for i, color in enumerate(colors): plt.scatter(np.random.randn(1000), np.random.randn(1000), color=color, edgecolors='k') # Set the random seed for consistency np.random.seed(12) # Change the default colors #mpl.rcParams['axes.color_cycle'] = colors = brewer2mpl.get_map('Set2', 'qualitative', 7).mpl_colors #matplotlib.image.cmap = brewer2mpl.get_map('Set2', 'qualitative', 7).mpl_colormap # I happen to know that there are 7 default colors in matplotlib for i, color in enumerate(colors): plt.scatter(np.random.randn(1000), np.random.randn(1000), color=color, edgecolors='grey',linewidths=0.1) # For some reason, this doesn't work with mpl import matplotlib matplotlib.matplotlib_fname() %%bash mkdir ~/.matplotlib cd ~/.matplotlib wget http://matplotlib.org/_static/matplotlibrc cat ~/.matplotlib/matplotlibrc for color in colors: print mpl.colors.rgb2hex(color) ! cat ~/.matplotlib/matplotlibrc | grep axes.color_cycle ! cat ~/.matplotlib/matplotlibrc | grep axes.color_cycle from matplotlib.colors import LogNorm from pylab import * #normal distribution center at x=0 and y=5 x = randn(100000) y = randn(100000)+5 hist2d(x, y, bins=40, norm=LogNorm()) colorbar() show() from matplotlib.colors import LogNorm from pylab import * #normal distribution center at x=0 and y=5 x = randn(100000) y = randn(100000)+5 hist2d(x, y, bins=40, norm=LogNorm(), cmap=brewer2mpl.get_map('Greens', 'sequential', 8).mpl_colormap) colorbar() show() from matplotlib.colors import LogNorm from pylab import * #normal distribution center at x=0 and y=5 x = randn(100000) y = randn(100000)+5 # norm=LogNorm() tells the function to use a logscale for the z-values hist2d(x, y, bins=40, norm=LogNorm(), cmap=brewer2mpl.get_map('Greys', 'sequential', 8).mpl_colormap) colorbar() show() from numpy.random import uniform, seed from matplotlib.mlab import griddata import matplotlib.pyplot as plt import numpy as np # make up data. #npts = int(raw_input('enter # of random points to plot:')) seed(0) npts = 200 x = uniform(-2,2,npts) y = uniform(-2,2,npts) z = x*np.exp(-x**2-y**2) # define grid. xi = np.linspace(-2.1,2.1,100) yi = np.linspace(-2.1,2.1,200) # grid the data. zi = griddata(x,y,z,xi,yi,interp='linear') # contour the gridded data, plotting dots at the nonuniform data points. CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k') CS = plt.contourf(xi,yi,zi,15,cmap=plt.cm.rainbow, vmax=abs(zi).max(), vmin=-abs(zi).max()) plt.colorbar() # draw colorbar # plot data points. plt.scatter(x,y,marker='o',c='b',s=5,zorder=10) plt.xlim(-2,2) plt.ylim(-2,2) plt.title('griddata test (%d points)' % npts) from numpy.random import uniform, seed from matplotlib.mlab import griddata import matplotlib.pyplot as plt import numpy as np # make up data. #npts = int(raw_input('enter # of random points to plot:')) seed(0) npts = 200 x = uniform(-2,2,npts) y = uniform(-2,2,npts) z = x*np.exp(-x**2-y**2) # define grid. xi = np.linspace(-2.1,2.1,100) yi = np.linspace(-2.1,2.1,200) # grid the data. zi = griddata(x,y,z,xi,yi,interp='linear') # contour the gridded data, plotting dots at the nonuniform data points. CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k') # ---- This is the line we changed ---- # CS = plt.contourf(xi,yi,zi,15, cmap=brewer2mpl.get_map('RdBu', 'diverging', 8, reverse=True).mpl_colormap, vmax=abs(zi).max(), vmin=-abs(zi).max()) plt.colorbar() # draw colorbar # plot data points. plt.scatter(x,y,marker='o',c='b',s=5,zorder=10) plt.xlim(-2,2) plt.ylim(-2,2) plt.title('griddata test (%d points)' % npts) from numpy.random import uniform, seed from matplotlib.mlab import griddata import matplotlib.pyplot as plt import numpy as np # make up data. #npts = int(raw_input('enter # of random points to plot:')) seed(0) npts = 200 x = uniform(-2,2,npts) y = uniform(-2,2,npts) z = x*np.exp(-x**2-y**2) # define grid. xi = np.linspace(-2.1,2.1,100) yi = np.linspace(-2.1,2.1,200) # grid the data. zi = griddata(x,y,z,xi,yi,interp='linear') # contour the gridded data, plotting dots at the nonuniform data points. CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k') # ---- This is the line we changed ---- # CS = plt.contourf(xi,yi,zi,15, cmap=brewer2mpl.get_map('PRGn', 'diverging', 8, reverse=True).mpl_colormap, vmax=abs(zi).max(), vmin=-abs(zi).max()) plt.colorbar() # draw colorbar # plot data points. plt.scatter(x,y,marker='o',c='b',s=5,zorder=10) plt.xlim(-2,2) plt.ylim(-2,2) plt.title('griddata test (%d points)' % npts) import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib._png import read_png import matplotlib.colors from matplotlib.cbook import get_sample_data class RibbonBox(object): original_image = read_png(get_sample_data("Minduka_Present_Blue_Pack.png", asfileobj=False)) cut_location = 70 b_and_h = original_image[:,:,2] color = original_image[:,:,2] - original_image[:,:,0] alpha = original_image[:,:,3] nx = original_image.shape[1] def __init__(self, color): rgb = matplotlib.colors.colorConverter.to_rgb(color) im = np.empty(self.original_image.shape, self.original_image.dtype) im[:,:,:3] = self.b_and_h[:,:,np.newaxis] im[:,:,:3] -= self.color[:,:,np.newaxis]*(1.-np.array(rgb)) im[:,:,3] = self.alpha self.im = im def get_stretched_image(self, stretch_factor): stretch_factor = max(stretch_factor, 1) ny, nx, nch = self.im.shape ny2 = int(ny*stretch_factor) stretched_image = np.empty((ny2, nx, nch), self.im.dtype) cut = self.im[self.cut_location,:,:] stretched_image[:,:,:] = cut stretched_image[:self.cut_location,:,:] = \ self.im[:self.cut_location,:,:] stretched_image[-(ny-self.cut_location):,:,:] = \ self.im[-(ny-self.cut_location):,:,:] self._cached_im = stretched_image return stretched_image class RibbonBoxImage(BboxImage): zorder = 1 def __init__(self, bbox, color, cmap = None, norm = None, interpolation=None, origin=None, filternorm=1, filterrad=4.0, resample = False, **kwargs ): BboxImage.__init__(self, bbox, cmap = cmap, norm = norm, interpolation=interpolation, origin=origin, filternorm=filternorm, filterrad=filterrad, resample = resample, **kwargs ) self._ribbonbox = RibbonBox(color) self._cached_ny = None def draw(self, renderer, *args, **kwargs): bbox = self.get_window_extent(renderer) stretch_factor = bbox.height / bbox.width ny = int(stretch_factor*self._ribbonbox.nx) if self._cached_ny != ny: arr = self._ribbonbox.get_stretched_image(stretch_factor) self.set_array(arr) self._cached_ny = ny BboxImage.draw(self, renderer, *args, **kwargs) if 1: from matplotlib.transforms import Bbox, TransformedBbox from matplotlib.ticker import ScalarFormatter fig = plt.gcf() fig.clf() ax = plt.subplot(111) years = np.arange(2004, 2009) box_colors = [(0.8, 0.2, 0.2), (0.2, 0.8, 0.2), (0.2, 0.2, 0.8), (0.7, 0.5, 0.8), (0.3, 0.8, 0.7), ] heights = np.random.random(years.shape) * 7000 + 3000 fmt = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(fmt) for year, h, bc in zip(years, heights, box_colors): bbox0 = Bbox.from_extents(year-0.4, 0., year+0.4, h) bbox = TransformedBbox(bbox0, ax.transData) rb_patch = RibbonBoxImage(bbox, bc, interpolation="bicubic") ax.add_artist(rb_patch) ax.annotate(r"%d" % (int(h/100.)*100), (year, h), va="bottom", ha="center") patch_gradient = BboxImage(ax.bbox, interpolation="bicubic", zorder=0.1, ) gradient = np.zeros((2, 2, 4), dtype=np.float) gradient[:,:,:3] = [1, 1, 0.] gradient[:,:,3] = [[0.1, 0.3],[0.3, 0.5]] # alpha channel patch_gradient.set_array(gradient) ax.add_artist(patch_gradient) ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) fig.savefig('ribbon_box.png') plt.show() import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib._png import read_png import matplotlib.colors from matplotlib.cbook import get_sample_data class RibbonBox(object): original_image = read_png(get_sample_data("Minduka_Present_Blue_Pack.png", asfileobj=False)) cut_location = 70 b_and_h = original_image[:,:,2] color = original_image[:,:,2] - original_image[:,:,0] alpha = original_image[:,:,3] nx = original_image.shape[1] def __init__(self, color): rgb = matplotlib.colors.colorConverter.to_rgb(color) im = np.empty(self.original_image.shape, self.original_image.dtype) im[:,:,:3] = self.b_and_h[:,:,np.newaxis] im[:,:,:3] -= self.color[:,:,np.newaxis]*(1.-np.array(rgb)) im[:,:,3] = self.alpha self.im = im def get_stretched_image(self, stretch_factor): stretch_factor = max(stretch_factor, 1) ny, nx, nch = self.im.shape ny2 = int(ny*stretch_factor) stretched_image = np.empty((ny2, nx, nch), self.im.dtype) cut = self.im[self.cut_location,:,:] stretched_image[:,:,:] = cut stretched_image[:self.cut_location,:,:] = \ self.im[:self.cut_location,:,:] stretched_image[-(ny-self.cut_location):,:,:] = \ self.im[-(ny-self.cut_location):,:,:] self._cached_im = stretched_image return stretched_image class RibbonBoxImage(BboxImage): zorder = 1 def __init__(self, bbox, color, cmap = None, norm = None, interpolation=None, origin=None, filternorm=1, filterrad=4.0, resample = False, **kwargs ): BboxImage.__init__(self, bbox, cmap = cmap, norm = norm, interpolation=interpolation, origin=origin, filternorm=filternorm, filterrad=filterrad, resample = resample, **kwargs ) self._ribbonbox = RibbonBox(color) self._cached_ny = None def draw(self, renderer, *args, **kwargs): bbox = self.get_window_extent(renderer) stretch_factor = bbox.height / bbox.width ny = int(stretch_factor*self._ribbonbox.nx) if self._cached_ny != ny: arr = self._ribbonbox.get_stretched_image(stretch_factor) self.set_array(arr) self._cached_ny = ny BboxImage.draw(self, renderer, *args, **kwargs) if 1: from matplotlib.transforms import Bbox, TransformedBbox from matplotlib.ticker import ScalarFormatter fig = plt.gcf() fig.clf() ax = plt.subplot(111) years = np.arange(2004, 2009) box_colors = [(0.8, 0.2, 0.2), (0.2, 0.8, 0.2), (0.2, 0.2, 0.8), (0.7, 0.5, 0.8), (0.3, 0.8, 0.7), ] heights = np.random.random(years.shape) * 7000 + 3000 fmt = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(fmt) for year, h, bc in zip(years, heights, box_colors): bbox0 = Bbox.from_extents(year-0.4, 0., year+0.4, h) bbox = TransformedBbox(bbox0, ax.transData) rb_patch = RibbonBoxImage(bbox, bc, interpolation="bicubic") ax.add_artist(rb_patch) ax.annotate(r"%d" % (int(h/100.)*100), (year, h), va="bottom", ha="center") # patch_gradient = BboxImage(ax.bbox, # interpolation="bicubic", # zorder=0.1, # ) # gradient = np.zeros((2, 2, 4), dtype=np.float) # gradient[:,:,:3] = [1, 1, 0.] # gradient[:,:,3] = [[0.1, 0.3],[0.3, 0.5]] # alpha channel # patch_gradient.set_array(gradient) # ax.add_artist(patch_gradient) ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) fig.savefig('ribbon_box.png') plt.show() import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib._png import read_png import matplotlib.colors from matplotlib.cbook import get_sample_data if 1: from matplotlib.transforms import Bbox, TransformedBbox from matplotlib.ticker import ScalarFormatter fig = plt.gcf() fig.clf() ax = plt.subplot(111) years = np.arange(2004, 2009) box_colors = [(0.8, 0.2, 0.2), (0.2, 0.8, 0.2), (0.2, 0.2, 0.8), (0.7, 0.5, 0.8), (0.3, 0.8, 0.7), ] heights = np.random.random(years.shape) * 7000 + 3000 fmt = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(fmt) for year, h, bc in zip(years, heights, box_colors): # bbox0 = Bbox.from_extents(year-0.4, 0., year+0.4, h) # bbox = TransformedBbox(bbox0, ax.transData) # rb_patch = BboxImage(bbox, interpolation='bicubic') # rb_ptch = RibbonBoxImage(bbox, bc, interpolation="bicubic") # ax.add_artist(rb_patch) # ax.add_artist(bbox) # --- this is the line we changed --- # ax.bar(year, h, color=bc) ax.annotate(r"%d" % (int(h/100.)*100), (year, h), va="bottom", ha="center") ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) fig.savefig('ribbon_box_no_ribbons.png') plt.show() import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib._png import read_png import matplotlib.colors from matplotlib.cbook import get_sample_data if 1: from matplotlib.transforms import Bbox, TransformedBbox from matplotlib.ticker import ScalarFormatter fig = plt.gcf() fig.clf() ax = plt.subplot(111) years = np.arange(2004, 2009) box_colors = brewer2mpl.get_map('Set1', 'qualitative', 5).mpl_colors # box_colors = [(0.8, 0.2, 0.2), # (0.2, 0.8, 0.2), # (0.2, 0.2, 0.8), # (0.7, 0.5, 0.8), # (0.3, 0.8, 0.7), # ] heights = np.random.random(years.shape) * 7000 + 3000 fmt = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(fmt) for year, h, bc in zip(years, heights, box_colors): # --- this is the line we changed --- # ax.bar(year-0.4, h, color =bc) ax.annotate(r"%d" % (int(h/100.)*100), (year, h), va="bottom", ha="center") ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) fig.savefig('ribbon_box_no_ribbons.png') plt.show() import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib._png import read_png import matplotlib.colors from matplotlib.cbook import get_sample_data if 1: from matplotlib.transforms import Bbox, TransformedBbox from matplotlib.ticker import ScalarFormatter fig = plt.gcf() fig.clf() ax = plt.subplot(111) years = np.arange(2004, 2009) box_colors = brewer2mpl.get_map('Set1', 'qualitative', 5).mpl_colors # box_colors = [(0.8, 0.2, 0.2), # (0.2, 0.8, 0.2), # (0.2, 0.2, 0.8), # (0.7, 0.5, 0.8), # (0.3, 0.8, 0.7), # ] heights = np.random.random(years.shape) * 7000 + 3000 fmt = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(fmt) for year, h, bc in zip(years, heights, box_colors): # --- this is the line we changed --- # ax.bar(year-0.4, h, color =bc) ax.annotate(r"%d" % (int(h/100.)*100), (year, h), va="bottom", ha="center") ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) fig.savefig('ribbon_box_no_ribbons.png') plt.show() import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib._png import read_png import matplotlib.colors from matplotlib.cbook import get_sample_data if 1: from matplotlib.transforms import Bbox, TransformedBbox from matplotlib.ticker import ScalarFormatter fig = plt.gcf() fig.clf() ax = plt.subplot(111) years = np.arange(2004, 2009) box_colors = brewer2mpl.get_map('Set1', 'qualitative', 5).mpl_colors # box_colors = [(0.8, 0.2, 0.2), # (0.2, 0.8, 0.2), # (0.2, 0.2, 0.8), # (0.7, 0.5, 0.8), # (0.3, 0.8, 0.7), # ] heights = np.random.random(years.shape) * 7000 + 3000 fmt = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(fmt) for year, h, bc in zip(years, heights, box_colors): # --- this is the line we changed --- # ax.bar(year-0.4, h, color =bc) ax.annotate(r"%d" % (int(h/100.)*100), (year, h+100), va="bottom", ha="center") ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) fig.savefig('ribbon_box_no_ribbons.png') plt.show() import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib._png import read_png import matplotlib.colors from matplotlib.cbook import get_sample_data if 1: from matplotlib.transforms import Bbox, TransformedBbox from matplotlib.ticker import ScalarFormatter fig = plt.gcf() fig.clf() ax = plt.subplot(111) years = np.arange(2004, 2009) # --- changed this line --- # box_colors = brewer2mpl.get_map('Set1', 'qualitative', 5).mpl_colors heights = np.random.random(years.shape) * 7000 + 3000 fmt = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(fmt) for year, h, bc in zip(years, heights, box_colors): # --- this is the line we changed --- # ax.bar(year-0.4, h, color =bc) ax.annotate(r"%d" % (int(h/100.)*100), (year, h+100), va="bottom", ha="center") ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) # --- Added this line --- # ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) fig.savefig('ribbon_box_no_ribbons.png') plt.show() import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib._png import read_png import matplotlib.colors from matplotlib.cbook import get_sample_data if 1: from matplotlib.transforms import Bbox, TransformedBbox from matplotlib.ticker import ScalarFormatter fig = plt.gcf() fig.clf() ax = plt.subplot(111) years = np.arange(2004, 2009) # --- changed this line --- # box_colors = brewer2mpl.get_map('Set1', 'qualitative', 5).mpl_colors heights = np.random.random(years.shape) * 7000 + 3000 fmt = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(fmt) for year, h, bc in zip(years, heights, box_colors): # --- this is the line we changed --- # ax.bar(year-0.4, h, color =bc) ax.annotate(r"%d" % (int(h/100.)*100), (year, h+100), va="bottom", ha="center") ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) # --- Added this line --- # ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) # --- Added this line --- # ax.yaxis.set_ticks_position('left') ax.xaxis.set_ticks_position('bottom') fig.savefig('ribbon_box_no_ribbons.png') plt.show() import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib._png import read_png import matplotlib.colors from matplotlib.cbook import get_sample_data if 1: from matplotlib.transforms import Bbox, TransformedBbox from matplotlib.ticker import ScalarFormatter fig = plt.gcf() fig.clf() ax = plt.subplot(111) years = np.arange(2004, 2009) # --- changed this line --- # box_colors = brewer2mpl.get_map('Set1', 'qualitative', 5).mpl_colors heights = np.random.random(years.shape) * 7000 + 3000 fmt = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(fmt) for year, h, bc in zip(years, heights, box_colors): # --- this is the line we changed --- # ax.bar(year-0.4, h, color =bc) ax.annotate(r"%d" % (int(h/100.)*100), (year, h+100), va="bottom", ha="center") ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) # --- Added this line --- # ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) # --- Added this line --- # ax.yaxis.set_ticks_position('none') ax.xaxis.set_ticks_position('none') ax.grid(axis = 'y', color ='white', linestyle='-') fig.savefig('ribbon_box_no_ribbons.png') plt.show() import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib._png import read_png import matplotlib.colors from matplotlib.cbook import get_sample_data if 1: from matplotlib.transforms import Bbox, TransformedBbox from matplotlib.ticker import ScalarFormatter fig = plt.gcf() fig.clf() ax = plt.subplot(111) years = np.arange(2004, 2009) # --- changed this line --- # box_colors = brewer2mpl.get_map('Set1', 'qualitative', 5).mpl_colors heights = np.random.random(years.shape) * 7000 + 3000 fmt = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(fmt) for year, h, bc in zip(years, heights, box_colors): # --- this is the line we changed --- # ax.bar(year-0.4, h, color=bc, linewidth=0) ax.annotate(r"%d" % (int(h/100.)*100), (year, h+100), va="bottom", ha="center") ax.set_xlim(years[0]-0.5, years[-1]+0.5) ax.set_ylim(0, 10000) # --- Added this line --- # ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) # --- Added this line --- # ax.yaxis.set_ticks_position('none') ax.xaxis.set_ticks_position('none') ax.grid(axis = 'y', color ='white', linestyle='-') fig.savefig('ribbon_box_no_ribbons.png') plt.show() # Find where my iPython directory is ! ipython locate # Show the contents of my custom.css file, which I created using the above tutorial ! cat /Users/olga/.ipython/profile_customcss/static/css/custom.css from bokeh.mpl import PlotClient p = PlotClient(username='defaultuser', serverloc="http://portcon:5006",userapikey="nokey") p.use_doc('example') p.notebooksources() x = np.arange(100) / 6.0 y = np.sin(x) z = np.cos(x) data_source = p.make_source(idx=range(100), x=x, y=y, z=z) p.hold('off') plot1 = p.plot('x', 'y', 'orange', data_source=data_source) plot2 = p.plot('x', 'z', 'blue', data_source=data_source) grid = p.grid([[plot1,plot2]]) grid