datamin and datamax in Viewer() did not work

风流意气都作罢 提交于 2021-02-08 10:20:22

问题


I used the above code in the fipy, but the range of color bar is always not changed( always showed [-1,1]). My version is Python 3.6.7 and matlablib 3.1.1.

#create a viewer to see the results
    if __name__ == '__main__':
        viewer = Viewer(vars=psi, datamin=-0.01, datamax=0)
        viewer.plot()

I tried the following: 1, I changed the code in "C:\Users\Lenovo\fipy\examples\diffusion", for example, changed "datamin=-0.01, datamax=0". is not work. 2, directly used "MatplotlibViewer". is not work. 3, used “GnuplotViewer". Can not install in Python.


回答1:


Currently, there is a bug in FiPy such that the datamin and datamax values are not used when rendering the colorbar for 2D plots. The issue is described here and here. There is a workaround, however.

This example renders a plot that should have three cells with max value above 3, but is cut off at 3.

from fipy import Grid2D, CellVariable, Viewer
from fipy.viewers.matplotlibViewer.matplotlibViewer import _ColorBar

m = Grid2D(nx=3, ny=3)

v = CellVariable(mesh=m)
v[:] = m.x * m.y

vi = Viewer(v, colorbar=None, datamin=0.0, datamax=3.0)
vi.colorbar = _ColorBar(viewer=vi, vmin=0.0, vmax=3.0)

vi.plot()

input('stopped')

It's necessary to use the datamin and datamax arguments and set the colorbar argument to None and then add the colorbar with the correct vmin and vmax values as these aren't being set correctly in FiPy.



来源:https://stackoverflow.com/questions/58469370/datamin-and-datamax-in-viewer-did-not-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!