利用Python中的numpy实现数据可视化功能(并运用tkinter使程序功能更加灵活)

代码如下:

from tkinter import *
import tkinter as tk

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']='SimHei'
plt.rcParams['axes.unicode_minus']=False

def function1():
    courses = np.array(['语文', '数学', '英语', '物理', '化学', '生物'])
    scores = np.array([[95, 75, 86],
                       [96, 93, 76],
                       [63, 85, 93],
                       [91, 88, 67],
                       [86, 76, 87]])
    data_length = len(scores)
    angles = np.linspace(0, 2 * np.pi, data_length, endpoint=False)
    scores = np.concatenate((scores, [scores[0]]))
    angles = np.concatenate((angles, [angles[0]]))
    plt.polar(angles, scores, 'o-', linewidth=3)
    plt.thetagrids(angles * 180 / np.pi, courses, fontproperties='simhei')
    plt.legend(['高二1班', '高二2班', '高二3班'], loc=(0.94, 0.80), labelspacing=0.1)
    plt.show()
def function2():
    courses = np.array(['语文', '数学', '英语', '物理', '化学', '生物'])
    scores1 = np.array([95, 96, 85, 63, 91, 86])
    scores2 = np.array([75, 93, 66, 85, 88, 76])
    scores3 = np.array([86, 76, 96, 93, 67, 87])
    x = [1, 2, 3, 4, 5, 6]
    plt.xticks(x, courses)
    plt.plot(x, scores1)
    plt.plot(x, scores2)
    plt.plot(x, scores3)
    plt.legend(['高二1班', '高二2班', '高二3班'], loc=(0.94, 0.80), labelspacing=0.1)
    plt.title("成绩评估")
    plt.show()
def function3():
    courses = np.array(['语文', '数学', '英语', '物理', '化学', '生物'])
    scores1 = np.array([95, 96, 85, 63, 91, 86])
    scores2 = np.array([75, 93, 66, 85, 88, 76])
    scores3 = np.array([86, 76, 96, 93, 67, 87])
    x = [1, 2, 3, 4, 5, 6]
    plt.xticks(x, courses)
    plt.scatter(x, scores1)
    plt.scatter(x, scores2)
    plt.scatter(x, scores3)
    plt.legend(['高二1班', '高二2班', '高二3班'], loc=(0.94, 0.80), labelspacing=0.1)
    plt.title("成绩评估")
    plt.show()
def function4():

    courses = np.array(['语文', '数学', '英语', '物理', '化学', '生物'])

    scores1 = np.array([95, 96, 85, 63, 91, 86])

    scores2 = np.array([75, 93, 66, 85, 88, 76])

    scores3 = np.array([86, 76, 96, 93, 67, 87])

    x = np.linspace(0, 6, 6)

    plt.xticks(x, courses)

    width = 0.15

    plt.bar(x - width, scores1, width=0.15)

    plt.bar(x, scores2, width=0.15)

    plt.bar(x + width, scores3, width=0.15)

    plt.legend(['高二1班', '高二2班', '高二3班'], loc=(0.94, 0.80), labelspacing=0.1)

    plt.title("成绩评估")

    plt.show()

win = tk.Tk()

win.title("图表")

win.geometry("300x85")

b01=Button(win, text="雷达图", command=function1).place(x=0, y=5, width=75, height=75)

b02 = Button(win, text="折线图",command=function2).place(x=75,y=5,width=75,height=75)

b03 = Button(win, text="散点图",command=function3).place(x=150,y=5,width=75,height=75)

b04 = Button(win, text="柱状图",command=function4).place(x=225,y=5,width=75,height=75)

win.mainloop()

在刚编写完可视化部分的代码后,运行时我发现四个图表是按照固定顺序依次显示的。于是我在可视化部分的代码的基础上,又添加了一个tkinter的页面,点击对应按钮,就可以打开对应的可视化图表,且关闭图表之后还可以再打开,使程序功能更加灵活。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python实现电影票房可视化系统的主要功能包括以下几个方面: 1. 数据采集:通过Python的网络爬虫技术,从电影票房相关网站获取电影票房数据。可以使用第三方库如BeautifulSoup或Scrapy来实现数据采集,获取电影的票房、排片数量、上座率等相关信息。 2. 数据存储:将采集到的电影票房数据存储到数据库,可使用Python的数据库操作库如MySQLdb或SQLAlchemy来实现数据存储。可以设计电影票房表、影院表、电影表等相关表结构。 3. 数据处理:通过Python的数据处理和分析库如Pandas、NumPy等对电影票房数据进行清洗、过滤、转换等操作,以便后续可视化展示。 4. 数据可视化利用Python的可视化库如Matplotlib、Seaborn等,将处理好的数据以图形化的方式展示出来。可以设计柱状图、折线图、散点图等形式,展示电影票房的变化趋势、不同电影的票房对比、地区票房排名等信息。 5. 用户交互:通过Python的GUI库如Tkinter、PyQt等,实现用户与系统之间的交互界面。用户可以选择查看不同时间段的电影票房情况、地区的票房排行、不同影院的票房对比等。还可以提供搜索功能,方便用户查找特定电影的票房情况。 总之,用Python实现电影票房可视化系统,通过数据采集、数据存储、数据处理、数据可视化和用户交互等功能,可以方便地呈现电影票房的相关信息,帮助用户了解电影市场的动态变化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值