houdini, python3 and matplotlib

   2592   6   3
User Avatar
Member
45 posts
Joined: Nov. 2019
Offline
Hello,

I recently installed the python3 beta of houdini and I wanted to use pytorch and matplotlib.
After placing all the packages into /install/python/lib/python3.7/site-packages I can call both library without triggering any error.

However the tutorial I was following used matplotlib.pylot to show a graph (pictures). So I call pyplot.imshow() and pyplot.show() and the image shows up in a separate window so I can play around with it.
The issue is that houdini freeze as soon as the figure window opens and even after I close it. My only option is use grep and kill to restart houdini.

Is anyone having the same issue ?

Any help appreciated, thanks.
User Avatar
Member
36 posts
Joined: Dec. 2016
Offline
I ran into the same issue. Try saving out the image instead with matplotlib.pyplot.savefig()
FYI, look up the proper way to do this with matplotlib.pyplot.close() so that you're not saving a new image on top of the old image as you can get overlayed graphs and odd behavior.
User Avatar
Member
62 posts
Joined: Sept. 2014
Offline
Try Toyplot, https://toyplot.readthedocs.io [toyplot.readthedocs.io] … it can send your plots to a web browser, and won’t interfere with the Houdini UI.

And yes, I admit it - I’m the original Toyplot developer.

Cheers,
Tim
User Avatar
Member
45 posts
Joined: Nov. 2019
Offline
Thanks both of you.
toyplot works great, congrats on being the founder of such an amazing tool.
User Avatar
Member
45 posts
Joined: Nov. 2019
Offline
tshead
Try Toyplot, https://toyplot.readthedocs.io [toyplot.readthedocs.io] … it can send your plots to a web browser, and won’t interfere with the Houdini UI.

And yes, I admit it - I’m the original Toyplot developer.

Cheers,
Tim

I used toyplot over week end and it worked great, thanks a lot.
However it seems that calling it from inside a PDG prevent it from creating a window in my browser.
If you have a work around that, that would be great.

I put the hip file in attachment, I moved back to houdini python2 atm and call python3 like canonball900 showed me here [www.sidefx.com].

Thanks again.

Attachments:
sin.hiplc (31.0 KB)

User Avatar
Member
36 posts
Joined: Dec. 2016
Offline
Here's an implementation of ToyPlot that I tried out and worked for me:

def img_convert(tensor):
image = tensor.cpu().clone().detach().numpy()
image = image.transpose(1, 2, 0)
image = image * np.array((0.5, 0.5, 0.5)) + np.array((0.5, 0.5, 0.5))
image = image.clip(0, 1)
return image

img = Image.open('C:/Users/ryan/Documents/Current_Projects/Houdini_Projects/render/ML_PDG_v006_color.png')
img = transform(img)
img_show = img_convert(img)
canvas, mark = toyplot.image(img_show, width=300)
toyplot.browser.show(canvas)
User Avatar
Member
62 posts
Joined: Sept. 2014
Offline
kadeno
I used toyplot over week end and it worked great, thanks a lot.
However it seems that calling it from inside a PDG prevent it from creating a window in my browser.
If you have a work around that, that would be great.

Your file doesn’t work here, but my PDG-fu is not strong and I’m not sure how you debug out-of-process PDG. However my minimalist example (see attached) works from the Python shell as well as in-process and out-of-process PDGs. A couple of notes:

* Toyplot 0.18 is the last version to support Python 2, so you have to install it explicitly by version, unless you’re using Python 3 Houdini.

* I use Conda to manage Python instances, and you can see from the Python Shell in the screenshot that I’m pointing Houdini to load packages from my conda instance instead of copying packages into Houdini. This works fine for me on macOS, I can’t say whether it would work on other platforms.

Cheers,
Tim
Edited by tshead - May 25, 2020 21:06:25

Attachments:
Screen Shot 2020-05-25 at 7.00.56 PM.png (989.4 KB)

  • Quick Links