Saving a GPy plot as an image file
See original GitHub issueHow can I save a GPy plot/visualization to an image file? I am on a Linux system with no attached display, so this is my only option for viewing visualizations.
This is my current attempt:
import GPy
import numpy as np
# sample inputs and outputs
X = np.random.uniform(-3.,3.,(50,2))
Y = np.sin(X[:,0:1]) * np.sin(X[:,1:2])+np.random.randn(50,1)*0.05
# define kernel
ker = GPy.kern.Matern52(2,ARD=True) + GPy.kern.White(2)
# create simple GP model
m = GPy.models.GPRegression(X,Y,ker)
# optimize and plot
m.optimize(messages=True,max_f_eval = 1000)
GPy.plotting.change_plotting_library("matplotlib")
fig = m.plot()
fig.savefig("model.png")
I get an error on the fig = m.plot()
line:
Unable to access the X Display, is $DISPLAY set properly?
It seems like m.plot()
is trying to show the figure immediately. How can I avoid this and only write to an image file?
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
How to Save Plots To Image Files Using Matplotlib
pyplot. savefig() function. Simply pass the desired filename (and even location) and the figure will be stored on your disk.
Read more >How to Save a Plot to a File Using Matplotlib | Tutorial by Chartio
Learn how to save a plot to a file using Matplotlib, a plotting library for Python. In this tutorial, we'll show you to...
Read more >Saving Plots in R | Department of Statistics
A General Method Choose the format that you want to use. In this example, I'll save a plot as a JPG file, so...
Read more >Saving Plots in R as .JPEG / .PNG files (Data ... - YouTube
Today we will be looking at how to save your ggplot2 and other plot results as .PNG and .JPEG files in R.For similar...
Read more >Specifying and saving a figure with exact size in pixels
where the filename has the "png" extension in this example (but you must still specify the format with format='png' anyway as far as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have resolved the issue. Here is the code in case anyone else encounters the same problem:
where the key lines are
I found a workaround: If you print out the dictionary from
ax = m.plot(plot_limits=[-15, 15], samples=5)
, soprint(ax)
, we see that it contains a dictionary,the first entry of which is the matplotlib plot we want. So the following worked for me: