mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-06 10:25:17 +08:00
plotting 2 graphs fix
This commit is contained in:
parent
0cd62350b5
commit
03dc7c1692
@ -9,14 +9,16 @@ def plot_forecast(final_year, companies, noise, show_legend, point_style):
|
||||
x = np.arange(start_year, final_year + 1)
|
||||
year_count = x.shape[0]
|
||||
plt_format = ({"cross": "X", "line": "-", "circle": "o--"})[point_style]
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(1)
|
||||
for i, company in enumerate(companies):
|
||||
series = np.arange(0, year_count, dtype=float)
|
||||
series = series ** 2 * (i + 1)
|
||||
series += np.random.rand(year_count) * noise
|
||||
plt.plot(x, series, plt_format)
|
||||
ax.plot(x, series, plt_format)
|
||||
if show_legend:
|
||||
plt.legend(companies)
|
||||
return plt
|
||||
return fig
|
||||
|
||||
|
||||
gr.Interface(plot_forecast,
|
||||
|
@ -32,7 +32,6 @@ def encode_plot_to_base64(plt):
|
||||
with BytesIO() as output_bytes:
|
||||
plt.savefig(output_bytes, format="png")
|
||||
bytes_data = output_bytes.getvalue()
|
||||
plt.close()
|
||||
base64_str = str(base64.b64encode(bytes_data), 'utf-8')
|
||||
return "data:image/png;base64," + base64_str
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user