08-18-2020 08:25 AM
I'm using the Add Text.vi in order to add heat values to each tile on a tile plot but it does not look like there is any way to center the text (aline center for top/left). This is causing overflow of text between the tiles, see picture:
Does anyone know a solution for this (without decreasing text size) or if this functionality will be added to the Add Text.vi?
08-18-2020 04:32 PM
Are you adding that text as a single line or as individual items by specifying the X,Y coordinates? It looks like your values aren't well aligned to any cell, which makes me think its all one string with spaces. Have a look at how they implemented it here.. https://stackoverflow.com/questions/11917547/how-to-annotate-heatmap-with-text-in-matplotlib
Craig
08-19-2020 04:43 AM - edited 08-19-2020 04:45 AM
I'm using X, Y coordinates to specify the text for each cell. But I'm not sure you understood that this is in LabVIEW Advanced Plotting Toolkit or you meant that I should edit the Python files that the toolkit is using? I made an example vi to demonstrate the problem:
08-19-2020 11:42 AM - edited 08-19-2020 11:46 AM
Matplotlib is the underlying plotting library that APT enables you to use in LabVIEW. Matplotlib a python package, so in order to see if that functionality even exists in the underlying package, and could be supported in APT you will have to do some digging in the APT docs and possibly in python forums. Then you could implement the fix by adjusting the APT code to your needs. Note that the answer I linked to provides a few clues..
for y in range(data.shape[0]):
for x in range(data.shape[1]):
plt.text(x + 0.5, y + 0.5, '%.4f' % data[y, x],
horizontalalignment='center',
verticalalignment='center',
)
"horizontalalignment='centre'" suggest to me that there exists a native way in Matplotlib to do what you want. Perhaps just adding a VI that is similar to Add Text.vi but extends its features. See also - https://matplotlib.org/3.1.0/gallery/images_contours_and_fields/image_annotated_heatmap.html
But if your plots are as simple as your example then all you need to do is better define your x-offset to put the text in the right place. This won't handle wrapping or exact centring but is a quick fix.
Craig
08-25-2020 05:48 AM
The problem is that the APT python files is already compiled binaries in .pyd format. I looked at the source code for APT on GitHub: https://github.com/advancedplotting/aplot but it did not seem so trivial for me to fix and also to compile new .pyd files. Unfortunate the example I added was just to demonstrate the problem and the real usage needs it to be much more dynamic and that solution would not suffice.