0

I've got an array of values I want to plot on a 1D heatmap in mmatplotlib. I'm using contourf for this. My current code is this:

x = np.empty([2,values.shape[0]])
x[:,:] = values
ax1.contourf(x)

This plots a colourmap but using the position of each value in the 'value' array as its x coordinate. How can I specify the x values on this heatmap? (I found this code on stackoverflow, and in all honestly I'm not entirely sure how it works.)

TIF
  • 191
  • 1
  • 2
  • 11
  • The first thing to do if you find some code is to understand it. If it is not obvious what it does, take its individual components and look up the documentation. Looking into the `contour` documentation will allow you to find out that `contour` would usually take 3 arguments, `x,y,z`. If you supply all three of them, you will have complete control over the data range. – ImportanceOfBeingErnest Mar 19 '19 at 18:32
  • I have looked up what contourf does and how it works, the bit I'm stuck on is how to translate that to a 1D colour bar - I want just an x axis with bars that vary in colour, and I'm not sure how to put in y values for coordinates for that. – TIF Mar 19 '19 at 20:04
  • 1
    A contour is necessarily 2D. You might want to show a simple image instead, `plt.imshow()` – ImportanceOfBeingErnest Mar 19 '19 at 20:05
  • Ah I've found your answer using imshow to a similar, thanks! – TIF Mar 19 '19 at 20:25

0 Answers0