python柱状图类VisualMapOpts方法说明

# 这是一个类,继承了 `BasicOpts` 类
class VisualMapOpts(BasicOpts):
    # 初始化函数,定义了一些参数及其默认值。其中包括 range_color、range_size、和 range_opacity 等参数
    def __init__(
        self,
        is_show: bool = True,  # 是否显示视觉映射组件,默认为 True
        type_: str = "color",  # 视觉映射的类型,可选值为 "color" 或 "size",默认为 "color"
        min_: Numeric = 0,  # 传入数据的最小值,默认为 0
        max_: Numeric = 100,  # 传入数据的最大值,默认为 100
        range_text: Optional[Sequence] = None,  # 区间文字,可以是列表或元组,例如 ["low", "high"],默认为空
        range_color: Optional[Sequence[str]] = None,  # 区间颜色,可以是列表或元组,例如 ["#50a3ba", "#eac763", "#d94e5d"],默认为空
        range_size: Optional[Sequence[int]] = None,  # 区间大小,可以是列表或元组,例如 [20, 50],默认为空
        range_opacity: Union[Numeric, Sequence[Numeric]] = None,  # 区间透明度,可以是数字或列表或元组,例如 [0.3, 1],默认为空
        orient: str = "vertical",  # 组件方向,可选值为 "horizontal" 或 "vertical",默认为 "vertical"
        pos_left: Optional[str] = None,  # 组件的左侧距离,例如 "20%",默认为空
        pos_right: Optional[str] = None,  # 组件的右侧距离,例如 "20%",默认为空
        pos_top: Optional[str] = None,  # 组件的顶部距离,例如 "20%",默认为空
        pos_bottom: Optional[str] = None,  # 组件的底部距离,例如 "20%",默认为空
        padding: Union[int, Sequence[int]] = 5,  # 内部间距,默认为 5
        split_number: int = 5,  # 分割段数,默认为 5
        series_index: Union[Numeric, Sequence, None] = None,  # 控制只对某些系列进行映射,默认为空
        is_hover_link: bool = True,  # 鼠标悬停时是否启用联动高亮效果,默认为 True
        dimension: Optional[Numeric] = None,  # 指定 data 中哪个维度的数据用来映射,例如 0 或 "x",默认为空
        is_calculable: bool = True,  # 是否显示拖拽用的手柄(手柄可以用来调整选中范围),默认为 True
        is_piecewise: bool = False,  # 是否分段显示,默认为 False
        is_inverse: bool = False,  # 是否反转组件,默认为 False
        precision: Optional[int] = None,  # 数据的小数精度,例如 0 或 1,默认为空
        pieces: Optional[Sequence] = None,  # 分段信息,可以是列表或元组(仅当 is_piecewise 为 True 时有效),例如 [(0, 30), (30, 60), (60, 90)],默认为空
        out_of_range: Optional[Sequence] = None,  # 未在映射范围内的数据颜色,例如 "#999",默认为空
        item_width: int = 0,  # 分段控件单元的宽度(仅当 is_piecewise 为 True 且未指定宽度时有效),默认为 0
        item_height: int = 0,  # 分段控件单元的高度(仅当 is_piecewise 为 True 且未指定高度时有效),默认为 0
        background_color: Optional[str] = None,  # 组件背景颜色,默认为空
        border_color: Optional[str] = None,  # 组件边框颜色,默认为空
        border_width: int = 0,  # 组件边框宽度,默认为 0
        textstyle_opts: Union[TextStyleOpts, dict, None] = None,  # 文本样式设置,可为 TextStyleOpts 对象、字典或空值,默认为空
    ):
        # 初始化内部区间操作,并根据视觉映射类型设置不同的区间操作
        _inrange_op: dict = {}
        if type_ == "color":
            range_color = range_color or ["#50a3ba", "#eac763", "#d94e5d"]
            _inrange_op.update(color=range_color)
        elif type_ == "size":
            range_size = range_size or [20, 50]
            _inrange_op.update(symbolSize=range_size)
        if range_opacity is not None:
            _inrange_op.update(opacity=range_opacity)

        # 根据是否分段显示设置视觉映射类型
        _visual_typ = "piecewise" if is_piecewise else "continuous"

        # 根据是否分段显示及宽高未指定设置默认宽高
        if is_piecewise and item_width == 0 and item_height == 0:
            item_width, item_height = 20, 14
        elif item_width == 0 and item_height == 0:
            item_width, item_height = 20, 140

        # 存储参数到 opts 字典中
        self.opts: dict = {
            "show": is_show,
            "type": _visual_typ,
            "min": min_,
            "max": max_,
            "text": range_text,
            "textStyle": textstyle_opts,
            "inRange": _inrange_op,
            "calculable": is_calculable,
            "inverse": is_inverse,
            "precision": precision,
            "splitNumber": split_number,
            "dimension": dimension,
            "seriesIndex": series_index,
            "hoverLink": is_hover_link,
            "orient": orient,
            "left": pos_left,
            "top": pos_top,
            "bottom": pos_bottom,
            "right": pos_right,
            "padding": padding,
            "showLabel": True,
            "itemWidth": item_width,
            "itemHeight": item_height,
            "outOfRange": out_of_range,
            "backgroundColor": background_color,
            "borderColor": border_color,
            "borderWidth": border_width,
        }

        # 如果分段显示,则增加 pieces 参数
        if is_piecewise:
            self.opts.update(pieces=pieces)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要绘制Python Pyecharts的三重柱,可以使用Pyecharts库的Bar3D类进行操作。以下是一个简单的示例代码: ```python from pyecharts import options as opts from pyecharts.charts import Bar3D data = [ [0, 0, 0, 2], [0, 0, 1, 3], [0, 0, 2, 1], [0, 1, 0, 4], [0, 1, 1, 2], [0, 1, 2, 2], [0, 2, 0, 1], [0, 2, 1, 3], [0, 2, 2, 4], [1, 0, 0, 2], [1, 0, 1, 4], [1, 0, 2, 1], [1, 1, 0, 3], [1, 1, 1, 1], [1, 1, 2, 3], [1, 2, 0, 2], [1, 2, 1, 1], [1, 2, 2, 2], ] x_data = ["A", "B", "C"] y_data = ["X", "Y", "Z"] bar3d = ( Bar3D() .add( "", data, xaxis3d_opts=opts.Axis3DOpts(data=x_data), yaxis3d_opts=opts.Axis3DOpts(data=y_data), zaxis3d_opts=opts.Axis3DOpts(type_="value"), ) .set_global_opts( visualmap_opts=opts.VisualMapOpts(max_=5), title_opts=opts.TitleOpts(title="Python Pyecharts 三重柱"), ) ) bar3d.render("bar3d.html") ``` 此代码使用了Bar3D类来创建一个三维柱,通过add()方法添加数据和设置坐标轴样式,通过set_global_opts()方法设置表的全局选项,最后通过render()方法表输出到HTML文件中。您可以根据自己的需要修改数据和样式来绘制不同的三重柱。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [100例Python代码带你从入门到进阶!](https://blog.csdn.net/weixin_46089319/article/details/106686395)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Python还在用Matplotlib?out了 !发现一款手绘可视化神器!](https://blog.csdn.net/lovenankai/article/details/103286320)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值