Python 画图工具生成数据点图

不用将数据复制excel生成点图,python一键生成数据点图

import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
import datetime
x = [1,2,3,4,5,6,7,8,9,10] # 设置点图x轴数量
y = [10,50,70,20,30,100,500,1000,800,750] # 设置点图Y轴数据
choose = 'data'

    def create_scatter_chart(x, y, name):
        import matplotlib
        matplotlib.use('Agg')
        import matplotlib.pyplot as plt
        import matplotlib as mpl
        mpl.use('agg')

        plt.figure(figsize=(20, 6), dpi=200)

        # ax = plt.subplot(1, 1, 1)
        # ax.set_ylim(bottom=0.)

        plt.xlabel("Times")
        plt.ylabel("data")
        plt.title("Information" % file)
		
		# y轴数据从0开始到数据最大值 * 1.2 上下限
        plt.xlim(0, len(x))
        plt.ylim(0, int(max(y) * 1.2))
        plt.grid(True, linestyle='--', alpha=0.5)

 		# 将x轴分成对应等份
        x_scale = 40
        if len(x) > x_scale:
            x_number = []
            for i in range(len(x) // (len(x) // x_scale) + 1):
                x_number.append(i * (len(x) // x_scale))
            x_number.append(len(x))
            x_table = []
            for i in range(len(x) // (len(x) // x_scale) + 1):
                # x_table.append(x[i * (len(x) // 20)])
                x_table.append(i * (len(x) // x_scale))
            x_table.append(len(x))
        else:
            x_number = range(len(x))
            x_table = x
        plt.xticks(x_number, x_table)
        plt.scatter(range(len(y)), y, s=8)
        plt.savefig('%s_info.png' % (name), format='png')
        plt.close()
create_picture(x, y, choose)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值