prophet icon indicating copy to clipboard operation
prophet copied to clipboard

Plotting in fbprophet does not work under Windows with the Command Prompt

Open hassheh opened this issue 8 years ago • 11 comments

When I try to run my python script in command prompt, it throws the error given below, while it works fine in Ipython. The issue is closed in Matplotlib repository (https://github.com/matplotlib/matplotlib/issues/11016). They believe it is related to fbprophet.

INFO:matplotlib.backends._backend_tk:Could not load matplotlib icon: can't use "pyimage10" as iconphoto: not a photo image

 m = Prophet()
 m.fit(Dataframe)
 future = m.make_future_dataframe(periods= 80, freq= 'M')
 forecast = m.predict(future)
 m.plot(forecast)
 m.plot_components(forecast);

hassheh avatar Apr 13 '18 12:04 hassheh

I found out that using both m.plot(forecast) and m.plot_components(forecast) at the same time causes the "pyimage10" error. However, this does not solve my problem either. (https://github.com/matplotlib/matplotlib/issues/11016). I get no errors, but matplotlib does not pop up..

Glutch avatar Apr 13 '18 14:04 Glutch

@Glutch if running in the command prompt the plot would not pop up unless you explicitly tell matplotlib to show it. Try this:

fig = m.plot(forecast)
fig.show()

and then does it pop-up?

There certainly seems to be an issue here but I'm highly skeptical that it is an fbprophet issue since we're just doing pretty vanilla plotting with matplotlib and then returning the figure object. But let's try to see if we can come up with a reproducible failure that uses only matplotlib. I'll try to repro this on a windows machine but in the meantime, based on @Glutch 's comment I'm wondering if the issue only happens when plotting both of them? Does

fig1 = m.plot(forecast)
fig2 = m.plot_components(forecast)
fig1.show()
fig2.show()

error? Does

fig1 = m.plot(forecast)
fig1.show()
fig2 = m.plot_components(forecast)
fig2.show()

error?

bletham avatar Apr 16 '18 19:04 bletham

I have followed the official prophet "quick start guide" https://facebook.github.io/prophet/docs/quick_start.html#python-api

This does not pop up matplotlib

fig = m.plot(forecast)
fig.show()

Both of your code examples gives me the pyimage10 error. Sidenote: There is a small window that flashes very quickly. Could be matplotlib trying to accomplish something (Same as hassheh linked, but mine closes instantly)

Glutch avatar Apr 17 '18 07:04 Glutch

I tried

 fig = m.plot(forecast)
 fig.show()

Im only able to see a small window without any graph.

capture

The result is same for

fig1 = m.plot(forecast)
fig2 = m.plot_components(forecast)
fig1.show()
fig2.show()

fig1 = m.plot(forecast)
fig1.show()
fig2 = m.plot_components(forecast)
fig2.show()

hassheh avatar Apr 17 '18 07:04 hassheh

When I try this on the Anaconda prompt, I also have that fig.show() produces a blank window, but it does work for me if I actually import matplotlib and use the module's show command, like this:

from matplotlib import pyplot as plt
fig1 = m.plot(forecast)
fig2 = m.plot_components(forecast)
plt.show()

Does that work for you?

bletham avatar Apr 18 '18 17:04 bletham

At least for me, fig.show() not working is an issue in matplotlib; it also doesn't work with this code:

from matplotlib import pyplot as plt
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.plot([1, 2, 3], [1, 2, 3])
fig.show()

bletham avatar Apr 18 '18 20:04 bletham

plt.show()

Works for me. But it still throws the same error

INFO:matplotlib.backends._backend_tk:Could not load matplotlib icon: can't use "pyimage10" as iconphoto: not a photo image

It doesn't matter though as long as it works. Thanks.

hassheh avatar Apr 19 '18 07:04 hassheh

That seems to be logged at INFO level and not ERROR, so I'm guessing it's harmless.

bletham avatar Apr 20 '18 00:04 bletham

@Glutch This other page should help you out if you haven't already fixed this already.

Basically, the docs don't tell you that you need to import matplotlib.pyplot as plt and use it to plot the figure.

steele232 avatar Aug 16 '18 15:08 steele232

Adding %matplotlib inline in my notebook helped fwiw

vr00n avatar Feb 09 '19 04:02 vr00n

plt.show() got it fixed

mj-01 avatar Jul 24 '19 13:07 mj-01