如何使用NREL的Floris库绘制带右侧侧栏图例的风尾流模拟结果图
Floris尾流模拟可视化添加侧边图例解决方案
你只需要捕获visualize_cut_plane返回的等值面绘图对象,再调用matplotlib的colorbar方法绑定到对应坐标轴即可,修改后的代码如下:
import matplotlib.pyplot as plt import floris.tools as wfct # Initialize the FLORIS interface fi # For basic usage, the florice interface provides a simplified interface to # the underlying classes file_dir = '...\example_input.json' fi = wfct.floris_interface.FlorisInterface(file_dir) # Calculate wake fi.calculate_wake() # Get horizontal plane at default height (hub-height) hor_plane = fi.get_hor_plane() # Plot and show fig, ax = plt.subplots() # 捕获返回的绘图对象 im = wfct.visualization.visualize_cut_plane(hor_plane, ax=ax) # 添加侧边图例,label内容可根据需求修改为对应物理量和单位 fig.colorbar(im, ax=ax, label='风速 (m/s)') plt.show()
补充说明:
visualize_cut_plane函数默认返回的是matplotlib的QuadMesh对象,刚好可以作为colorbar的输入参数- 如果你需要调整图例的样式、位置、刻度,直接修改
fig.colorbar的参数即可,比如添加shrink=0.8参数调整图例高度,添加orientation='horizontal'参数改为水平放置图例
内容的提问来源于stack exchange,提问作者Josue9740
相关产品推荐
相关产品推荐

