是否可以在同一图形上绘制两条线?我在Jupyter上使用Panel。但是,我只能在两条不同的图形上绘制两条线。我想在更改输入值的同时将所有图形都放在同一张图上以比较结果。
我不在乎是否必须使用Panel,Bokeh,Holoview等
最好的问候,VQ
import panel as pn
pn.extension()
import panel.widgets as pnw
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def mplplot(df, **kwargs):
fig = df.plot(title='Title - Convert temperature from degree Celsius to Kelvin')
fig.legend(["Temperature"]);
fig.set_xlabel("Celcius")
fig.set_ylabel("Kelvin")
fig= fig.get_figure()
plt.close(fig)
return fig
def Celsius_to_Kelvin(C=100, view_fn=mplplot):
C = np.arange(0,C, 1)
K = (C + 273.15)
df = pd.DataFrame(dict(y=K), index=C)
return view_fn(df, K=K, C=C)
def Celsius_to_Kelvin1(C=100, view_fn=mplplot):
C = np.arange(0,C, 1)
K = (C + 273.15)
df = pd.DataFrame(dict(y=K), index=C)
return view_fn(df, K=K, C=C)
C = pnw.FloatSlider(name='C', value=50, start=0, end=100)
C1 = pnw.FloatSlider(name='C1', value=40, start=0, end=100)
@pn.depends(C.param.value)
def Celsius_to_Kelvin_variables(C):
return Celsius_to_Kelvin(C)
@pn.depends(C1.param.value)
def Celsius_to_Kelvin_variables1(C1):
return Celsius_to_Kelvin1(C1)
widgets = pn.Column("<br>\n#### Variable configuration", C, C1)
Celsius_to_Kelvin_panel = pn.Row(Celsius_to_Kelvin_variables, Celsius_to_Kelvin_variables1, widgets)
Celsius_to_Kelvin_panel
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS80a2ZONi5wbmcifQ==” alt =“在此处输入图像描述”>“ >>
是否可以在同一图形上绘制两条线?我在Jupyter上使用Panel。但是,我只能在两条不同的图形上绘制两条线。我想将所有内容都放在同一张图上,以...
您几乎可以使用任何绘图库在同一图形上绘制两条线。为此,请按照所使用的任何绘图库的说明进行操作;面板将能够绘制出您想出的任何内容(但不包括在此类叠加层中)。在这里,您的代码使用的是Pandas .plot(),据我所知,它仅对同一数据帧中的数据进行叠加打印,但是您可以使用本机Matplotlib API直接创建打印图。参见例如https://python-graph-gallery.com/122-multiple-lines-chart/或Matplotlib文档。