Advanced Plotting Toolkit

cancel
Showing results for 
Search instead for 
Did you mean: 

Center text in the Add Text function

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:

RandomUserXXX_0-1597756897198.png

Does anyone know a solution for this (without decreasing text size) or if this functionality will be added to the Add Text.vi?

0 Kudos
Message 1 of 5
(2,662 Views)

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

0 Kudos
Message 2 of 5
(2,642 Views)

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:

RandomUserXXX_0-1597830050549.png

RandomUserXXX_1-1597830107506.png

 

 

0 Kudos
Message 3 of 5
(2,631 Views)

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. 

 

centre_text_apt.png

 

Craig

 

 

0 Kudos
Message 4 of 5
(2,624 Views)

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.

0 Kudos
Message 5 of 5
(2,592 Views)