【源码】plotly库绘制精美散点图

plotly库绘制精美散点图

代码

from scipy.optimize import curve_fit
from math import sqrt
import plotly.graph_objects as go
import numpy as np

x1 = np.random.random(100) * 100
y1 = np.linspace(500, 1000, 100)

x2 = np.random.random(100) * 150
y2 = np.linspace(1000, 2000, 100)

fig = go.Figure()
fig.add_trace(
    go.Scatter(
        name="legend 1",
        x=x1,
        y=y1,
        mode="markers",
        marker=dict(
            color='rgba(120, 110, 90, 1)',
            size=12,
            symbol="diamond",
            # cmin=0,
            # cmax=150,
            # autocolorscale=True,
            # showscale=True,
            line=dict(
                width=10,
                color='rgba(120, 70, 50, 0.3)'
            )
        ),
        text="legend 1",
        textposition="top center"
    ))

fig.add_trace(
    go.Scatter(
        name="legend 2",
        x=x2,
        y=y2,
        mode="markers",
        marker=dict(
            color='rgba(50, 120, 160, 1)',
            size=12,
            symbol="circle",
            # cmin=0,
            # cmax=150,
            # colorscale='Electric',
            # showscale=True,
            line=dict(
                width=10,
                color='rgba(60, 110, 120, 0.3)'
            )
        ),
        text="legend 2",
        textposition="top center"
    ))

fig.update_layout(
    font=dict(family="Times New Roman",
              size=16,
              # color="RebeccaPurple",
              ),
    title="散点示例",
    title_x=0.5,
    title_y=0.95,
    xaxis=dict(title="x轴",
               nticks=50,
               showgrid=True,
               showline=True,
               showticklabels=True,
               # gridwidth=1,
               # zeroline=True,
               tickangle=0,
               linecolor='#636363',
               # tickmode = 'linear'
               # tick0 = 0,
               # dtick = 1
               ),
    yaxis=dict(title="y轴",
               # nticks=50,  # y轴刻度数量
               tick0=500,    # nticks, rangemode 和 range的优先级都比它俩的
               dtick=200,
               linecolor='#636363',
               showgrid=True,
               showline=True,
               showticklabels=True,
               mirror=True,  # 是否设置两个Y轴
               # range=(0, 2500),
                # rangemode="tozero",
               zeroline=False,
               gridwidth=1,
               ),
    legend={
        'x': 0.35,
        'y': 1.065,
        'font': {
            'size': 18
        },
        'orientation': 'h'
    },
    width=1000,
    height=800,
    # paper_bgcolor='rgb(243, 243, 243)',
    # plot_bgcolor='rgb(243, 243, 243)',

    template='plotly_white'  # plotly_dark   plotly_white  presentation
)

fig.show()
# fig.write_image("第{}组_{}.png".format(num + 1, job_type[index]), scale=5)

运行结果

请添加图片描述

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值