pyecharts / pyecharts-gallery

Just use pyecharts to imitate Echarts official example.
https://gallery.pyecharts.org
MIT License
1.19k stars 585 forks source link

Bar3D 坐标和 Bar 发生了奇怪的偏移,Strange shift between the bar and axis #22

Closed WenyinWei closed 2 years ago

WenyinWei commented 4 years ago
import pyecharts.options as opts
from pyecharts.charts import Bar3D
coilsys, coil = 'HCFs', 'c'

s_ind = -20
m_, n_ = range(-11, 11 +1), range(-3, 3 +1)
data_ = [[m,n,np.abs(Bcomp_smn[coilsys][coil]['b1_bis'][s_ind,m,n])] for m in m_ for n in n_]
data_max=max([data[2] for data in data_])/3
bar = ( Bar3D() # init_opts=opts.InitOpts(width="1000px", height="500px")
            .add(
                series_name="",
                data=data_,
                xaxis3d_opts=opts.Axis3DOpts(type_="category", name='m', data=m_),
                yaxis3d_opts=opts.Axis3DOpts(type_="category", name='n', data=n_),
                zaxis3d_opts=opts.Axis3DOpts(type_="value"),
                grid3d_opts=opts.Grid3DOpts(width=len(m_)*6, height=40, depth=len(n_)*6),
            )
            .set_global_opts(
                visualmap_opts=opts.VisualMapOpts(max_=data_max)
            )
)
bar.render_notebook()

这一段代码可以产生这样的图,

image

但如果我将它打包成函数的话,就会产生下面奇怪的偏移,

from ergospy.visual import RMP
coilsys, coil = 'HCFs', 'c'
s_ind = -5
m_, n_ = range(0, 15 +1),[-3,-2,-1,0, 1,2,3]
bar3D = RMP.spectrum_bar3D(np.abs(Bcomp_smn[coilsys][coil]['b1_bis'][s_ind,:,:]), m_,n_, 1/2)
bar3D.render_notebook()

image

WenyinWei commented 4 years ago

不合适的坐标类型似乎也会产生问题,如果我将 n 的范围 range(-4, 4 +1) 改为 [-4,-3,-2,-1,0,1,2,3,4],也会出现这样的问题

import pyecharts.options as opts
from pyecharts.charts import Bar3D
coilsys, coil = 'HCFs', 'c'

s_ind = -20
m_, n_ = range(-11, 11 +1), [-4,-3,-2,-1,1,2,3,4] # range(-4, 4 +1) 
data_ = [[n,m,np.abs(Bcomp_smn[coilsys][coil]['b1_bis'][s_ind,m,n])] for m in m_ for n in n_]
data_max=max([data[2] for data in data_])/3
bar = ( Bar3D() # init_opts=opts.InitOpts(width="1000px", height="500px")
            .add(
                series_name="",
                data=data_,
                xaxis3d_opts=opts.Axis3DOpts(type_="category", name='n', data=n_),
                yaxis3d_opts=opts.Axis3DOpts(type_="category", name='m', data=m_),
                zaxis3d_opts=opts.Axis3DOpts(type_="value"),
                grid3d_opts=opts.Grid3DOpts(width=len(n_)*6, height=40, depth=len(m_)*6),
            )
            .set_global_opts(
                visualmap_opts=opts.VisualMapOpts(max_=data_max)
            )
)
bar.render_notebook()

image