python matplotlib : plot vertical_barplotcolor with classes -
i'm looking tips or 2 make vertical parallel barplot (or rectangles) different colours according data.
example, plot of data = [1,1,1,2,2,1,3,3,3,2,2,2,3,3,3,3]
like:
that done matplotlib. following code produces result above
import matplotlib.pyplot plt import numpy np data = [1,1,1,2,2,1,3,3,3,2,2,2,3,3,3,3] col= [none, '#1620c0', '#e11239', '#2f9007' ] colors = [col[d] d in data] fig = plt.figure(figsize=(5,4)) ax = fig.add_axes([0,0,1,1]) # create bar plot # postions of bars , 1 in height , 1 in width , color according data, no line ax.bar(np.arange(len(data)), np.ones(len(data)), np.ones(len(data)), color=colors, linewidth=0 ) plt.axis('off') plt.show()
update:
in case need picture of 8 x 5000 pixels, need make sure save according resolution. following code produces png image of dimensions 8 x 5000.
import matplotlib.pyplot plt import numpy np data = np.random.randint(1,4, 5000) col= [none, '#1620c0', '#e11239', '#2f9007' ] colors = [col[d] d in data] fig = plt.figure(figsize=(5,8./1000)) ax = fig.add_axes([0,0,1,1]) ax.bar(np.arange(len(data)), np.ones(len(data)), np.ones(len(data)), color=colors, linewidth=0 ) plt.axis('off') plt.savefig("so_coloredbars.png", dpi=1000)
Comments
Post a Comment