1

I have a simulation tool which gives me temperature arrays as results. These temperature arrays are in each timestep 1D arrays. To visualize them (I've got alot of these temperature arrays which each represent a different part of my environment I simulate) I want to plot them with matplotlib. Since the parts represented by these arrays have different shapes, I need to plot the temperature arrays in these shapes and have the temperature on the Z-axis with a colorbar.
For my 2D-arrays this works great using a pcolormesh plot, but lines which are not horizontal or vertical will be shown aliased when plotted. Setting antialiased=True will help with that but instead produce big "blobs" which don't really look nice.

Is there any way to make the lines less "blobby" when using pcolormesh? My minimum working examples are below:

# temperature array
temp = np.arange(20, dtype=np.float64) + 25
# x and y vector along vertices (0, 0), (5, 15), (12, 16) and (0, 20):
x_vec = np.concatenate((np.linspace(0, 5, 7, endpoint=False), np.linspace(5, 12, 4, endpoint=False), np.linspace(12, 0, 9)))
y_vec = np.concatenate((np.linspace(0, 15, 7, endpoint=False), np.linspace(15, 16, 4, endpoint=False), np.linspace(16, 20, 9)))
# make diagonal matrix from temp for plotting:
t_dia = np.diag(temp)

# set 0 to nan for correct colorbar in pcolormesh:
t_dia[t_dia == 0] = np.nan
# and now plot pcolormesh:
fig2 = mp.figure()
ax2 = fig2.gca()
surf2 = ax2.pcolormesh(x_vec, y_vec, t_dia, linewidth=10, antialiased=True, edgecolors='None')
fig2.colorbar(surf2)

Thanks for your help in advance! (Since I'll be in the weekend now, I most probably won't be able to answer until monday.)

JE_Muc
  • 5,403
  • 2
  • 26
  • 41
  • It should be clear that you cannot ask two completely different questions at once. Their solutions are completely different. Which one would you like to be answered here? Remove the other from the question - possibly ask a different question about it. – ImportanceOfBeingErnest Dec 01 '17 at 18:52
  • Since at the end you want to plot a line in different colors, I marked as duplicate of the [existing question](https://stackoverflow.com/questions/17240694/python-how-to-plot-one-line-in-different-colors) about it. – ImportanceOfBeingErnest Dec 01 '17 at 19:06
  • Ok thanks for that hint, I removed the surface plot part. But still I don't think that it is a duplicate, since I need a colorbar for the temperature values. – JE_Muc Dec 01 '17 at 22:19
  • 1
    What would be the problem of getting that colorbar? – ImportanceOfBeingErnest Dec 01 '17 at 22:25
  • 1
    I marked as another duplicate which directly uses a colorbar. – ImportanceOfBeingErnest Dec 01 '17 at 22:34
  • Thanks, I'll take a look into it. Originally I wanted to be able to ad area plots later on, thus chose pcolormesh. But I'll try to do it with LineCollection for now. – JE_Muc Dec 01 '17 at 23:47
  • 1
    You may have a pcolormesh and a LineCollection in the same axes if that is what you're after. – ImportanceOfBeingErnest Dec 02 '17 at 11:50
  • Yeah, that was what I wanted to do, since some of my temperature arrays are 2D. :) Now I just need to add thin edges to my linecollection plots. I tried `edgecolors` but this does not seem to be implemented in `LineCollections`. Also corners in the lines are overlapping sharp corners. But this is not really important to me right now. So... Thanks for your help! – JE_Muc Dec 04 '17 at 09:50

0 Answers0