我尝试实现在我的环境模拟期间更新的 matplotlib 图。
以下类在我的测试中运行良好,但在我的环境中使用它时不会更新数字。在环境模拟期间,会显示图形,但未绘制线条。
我的猜测是 .draw() 没有像我认为的那样工作。
任何人都可以弄清楚这里的问题吗?
class Visualisation:
def __init__(self, graphs):
self.graphs_dict = {}
for graph in graphs:
fig = plt.figure()
ax = fig.add_subplot(111)
line, = ax.plot(graph.x, graph.y, 'r-')
self.graphs_dict[graph.title] = {"fig": fig, "ax": ax, "line": line, "graph": graph}
self.graphs_dict[graph.title]["fig"].canvas.draw()
plt.ion()
plt.show()
def update(self, graph):
graph = self.graphs_dict[graph.title]["graph"]
self.graphs_dict[graph.title]["line"].set_xdata(graph.x)
self.graphs_dict[graph.title]["line"].set_ydata(graph.y)
self.graphs_dict[graph.title]["fig"].canvas.flush_events()
x_lim, y_lim = self.get_lim(graph)
self.graphs_dict[graph.title]["ax"].set_xlim(x_lim)
self.graphs_dict[graph.title]["ax"].set_ylim(y_lim)
self.graphs_dict[graph.title]["fig"].canvas.draw()
@staticmethod
def get_lim(graph):
if graph.x_lim is None:
x = np.array(graph.x)
y = np.array(graph.y)
x_lim = [x.min(), x.max()]
y_lim = [y.min(), …
Run Code Online (Sandbox Code Playgroud) 我试图与我的一位同事交换我的 Modelica 模型,但在 CSV 文件的路径方面遇到了困难。
当我创建 FMU 时,一些 CSV 文件的路径被设置并指向我计算机上的文件夹。例如 C:/Users/Me/file.csv。这显然对我的同事不起作用。
如何以相对于用户设置路径的方式导出我的 Modelica 模型 (Dymola)?
我需要从 dymola 的建模对象中获得相当好的图像。由于模型的大小,截图/使用截图工具会导致图片质量很差。
有没有办法导出我在 dymola 中绘制的“图片”?
我试着用这样的东西:
使用Model1和带有参数的模型进行Toplevel.
Parametermodel:参数heat_coeffi = 50;
Model1:outer [Path:Parametermodel] name; 参数heat_coeffi = name.heatcoeffi;
错误消息是:"找到内部模型的非内部参数模型无法找到匹配的内部....
我尝试使用它就像他们使用原始Modelica Lib中的System一样.
我想通过将用户定义的参数与第一列的值进行比较来访问矩阵的特定行.
伪代码例如:
parameter Real userinput;
Real matrix[4,10] = [10,1,3,5; 3,1,5,9;.....];
Integer rowidentity;
for i in 1:10 loop
if matrix[1,i] = userinput then
i = rowidentity;
end if;
end for;
Run Code Online (Sandbox Code Playgroud)
从我所知道的循环或if语句不能在等式部分之外工作.
如果没有if或for循环,我怎么能做这个任务?
我尝试读取其中带有笑脸的聊天记录,但出现以下错误:
UnicodeDecodeError:“ charmap”编解码器无法解码位置38的字节0x9d:字符映射到
我的代码如下所示:
file_name = "chat_file.txt"
chat = open(chat_file)
chatText = chat.read() # read data
chat.close()
print(chatText)
Run Code Online (Sandbox Code Playgroud)
我可以肯定这是由于诸如以下的元素:
如何实现正确的转换格式//什么是正确的文件编码,以便python可以读取这些元素?
我正在尝试创建下图,但将月份写成 xticks 而不是整数:
我的代码目前看起来像这样:
plt.figure(figsize=(10,5))
sns.lineplot(x="Month",y="DHN",data = df.head(1100),color="BLACK")
sns.lineplot(x="Month",y="Heat Loss",data = df.head(1100),color ="RED")
Run Code Online (Sandbox Code Playgroud)
结果是:
显然,这张图有很多地方是错误的。图表 x 轴应该从一月开始,数据框内的值在几个月内堆积起来(?),并且df.head(1100)
不应该包括像十二月或九月这样的月份。
数据框的第一行如下所示:
以日期作为日期时间。
我错过了什么,它没有按照我想要的方式工作?
dymola ×4
modelica ×3
python ×2
fmi ×1
iso-8859-1 ×1
matplotlib ×1
openmodelica ×1
pandas ×1
python-3.x ×1
seaborn ×1
simulation ×1
text ×1