How to decouple hatch and edge color in matplotlib?

Plot bar plot twice: import matplotlib.pyplot as plt from matplotlib.patches import Ellipse, Polygon fig = plt.figure() ax1 = fig.add_subplot(111) # draw hatch ax1.bar(range(1, 5), range(1, 5), color=”none”, edgecolor=”red”, hatch=”https://stackoverflow.com/”, lw=1., zorder = 0) # draw edge ax1.bar(range(1, 5), range(1, 5), color=”none”, edgecolor=”k”, zorder=1, lw=2.) ax1.set_xticks([1.5, 2.5, 3.5, 4.5]) plt.show()

Python with matplotlib – drawing multiple figures in parallel

There are several ways to do this, and the simplest is to use the figure numbers. The code below makes two figures, #0 and #1, each with two lines. #0 has the points 1,2,3,4,5,6, and #2 has the points 10,20,30,40,50,60. from pylab import * figure(0) plot([1,2,3]) figure(1) plot([10, 20, 30]) figure(0) plot([4, 5, 6]) figure(1) … Read more

How to display print statements interlaced with matplotlib plots inline in Ipython?

There is simple solution, use matplotlib.pyplot.show() function after plotting. this will display graph before executing next line of the code %matplotlib inline import matplotlib.pyplot as plt i = 0 for data in manydata: fig, ax = plt.subplots() print “data number i =”, i ax.hist(data) plt.show() # this will load image to console before executing next … Read more

How to make xticks evenly spaced despite their value?

You can do it by plotting your variable as a function of the “natural” variable that parametrizes your curve. For example: n = 12 a = np.arange(n) x = 2**a y = np.random.rand(n) fig = plt.figure(1, figsize=(7,7)) ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212) ax1.plot(x,y) ax1.xaxis.set_ticks(x) ax2.plot(a, y) #we plot y as a function of a, … Read more

Colorbar for matplotlib plot_surface command

You can use a proxy mappable object since your surface array is not mapped. The mappable simply converts the values of any array to RGB colors defined by a colormap. In your case you want to do this with the z1 array: import matplotlib.cm as cm m = cm.ScalarMappable(cmap=cm.jet) m.set_array(z1) plt.colorbar(m)

Sorting the order of bars in pandas/matplotlib bar plots

You’ll have to provide a mapping to specify how to order the day names. (If they were stored as proper dates, there would be other ways to do this.) Updated: Build the key. You could write out a dictionary explicitly or use something clever like this dict comprehension. weekdays = [‘Mon’, ‘Tues’, ‘Weds’, ‘Thurs’, ‘Fri’, … Read more