python - Avoid change of figure size when adding plot() to imshow() -


i want add line plot() color map made imshow() in matplotlib, several sub-figures of different sizes assumed. when adding line, color map somehow changes size. how around this?

here simple example illustrating problem:

import scipy.stats       stat import matplotlib.pyplot plt import matplotlib.cm     cm import numpy             np  fig = plt.figure(figsize=(12, 4)) plt.axes([.05,.1,.4,.8]) data = stat.uniform.rvs(size=2400).reshape((40,60)) plt.imshow(data,cmap=cm.jet,vmin=0,vmax=1) plt.colorbar(fraction=.03) plt.plot(range(60),20*np.ones(60),'w-',lw=3)  #  <-- causing problems plt.title('the damn white line') 

you can avoid command plt.autoscale(false) after first plot.

also, in opinion, better solution use plt.axhline rather plt.plot make horizontal line, axhline spans whole horizontal extent of axes, if pan/zoom in plot.

in other words, example rewritten this:

import scipy.stats       stat import matplotlib.pyplot plt import matplotlib.cm     cm import numpy             np  data = stat.uniform.rvs(size=2400).reshape((40,60))  plt.figure(figsize=(12, 4)) plt.axes([.05,.1,.4,.8]) plt.imshow(data,cmap=cm.jet,vmin=0,vmax=1) plt.colorbar(fraction=.03) plt.autoscale(false) plt.axhline(y=20, c='w', lw=3) plt.title('the damn white line') 

enter image description here


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -