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