吴裕雄 实战PYTHON编程(6)

import matplotlib.pyplot as plt

plt.rcParams[‘font.sans-serif‘]=[‘Simhei‘]
plt.rcParams[‘axes.unicode_minus‘]=False

listx1 = [1,5,7,9,13,16]
listy1 = [15,50,80,40,70,50]
plt.bar(listx1, listy1, label="男性")
listx2 = [2,6,8,11,14,16]
listy2 = [10,40,30,50,80,60]
plt.bar(listx2, listy2, color="red", label="女性")
plt.legend()
plt.xlim(0, 20)
plt.ylim(0, 100)
plt.title("零花钱统计")
plt.xlabel("年龄")
plt.ylabel("零花钱数量")
plt.show()

import matplotlib.pyplot as plt

listx = [1,5,7,9,13,16]
listy = [15,50,80,40,70,50]
plt.plot(listx, listy, color ="red")
plt.show()

import matplotlib.pyplot as plt

listx1 = [1,5,7,9,13,16]
listy1 = [15,50,80,40,70,50]
plt.plot(listx1, listy1, label="Male")
listx2 = [2,6,8,11,14,16]
listy2 = [10,40,30,50,80,60]
plt.plot(listx2, listy2, color="red", linewidth=5.0, linestyle="--", label="Female")
plt.legend()
plt.xlim(0, 20)
plt.ylim(0, 100)
plt.title("Pocket Money")
plt.xlabel("Age")
plt.ylabel("Money")
plt.show()

import matplotlib.pyplot as plt

labels = ["东部", "南部", "北部", "中部"]
sizes = [5, 10, 20, 15]
colors = ["red", "green", "blue", "yellow"]
explode = (0, 0, 0.05, 0)
plt.pie(sizes,explode = explode,labels = labels,colors = colors,\
labeldistance = 1.1,autopct = "%3.1f%%",shadow = True,\
startangle = 90,pctdistance = 0.6)
plt.axis("equal")
plt.legend()
plt.show()

import numpy as np
import matplotlib.pyplot as plt #导入绘图模块,重命名为plt
import requests #导入网页内容抓取包
from bs4 import BeautifulSoup as bs #导入网页解析模块,重命名为bs
from pylab import * #导入pylab包

rcParams[‘font.sans-serif‘] = [‘SimHei‘] #让matplotlib支持简体中文

year = [] #横坐标列表
gdp = [] #纵坐标列表
#url = "http://value500.com/M2GDP.html" #设置要在哪个网页抓数据
url = "http://value500.com/M2GDP.html"
content = requests.get(url) #获取网页内容
print(content)
content.encoding=‘utf-8‘ #转为utf-8编码
content1=content.text #取得网页内容的text部分
parse = bs(content1,"html.parser") #进行html解析
data1 = parse.find_all("table") #获取所有表元素
rows = data1[19].find_all("tr") #取出包含所需数据的表(网页第20个表)
i=0 #为了不读取表头数据,设置此控制变量
for row in rows:
cols = row.find_all("td") #把每一行表数据存入cols变量
if(len(cols) > 0 and i==0): #如果是第一行,则控制变量加1
i+=1
else: #如果不是第一行,则写入绘图列表
year.append(cols[0].text[:-2]) #取得年份数据(数据的最后两个字符不是数据需去除)并写入图形的year轴
gdp.append(cols[2].text) #把gdp值存入gdp轴
plt.plot(year, gdp, linewidth=2.0) #绘制图形,线宽为2
plt.title("1990~2016年度我国GDP") #设置图形标题
plt.xlabel("年度") #设置x轴标题
plt.ylabel("GDP(亿元)") #设置y轴标题
plt.show() #显示所绘图形

from bokeh.plotting import figure, show

p = figure(width=800, height=400)
listx = [1,5,7,9,13,16]
listy = [15,50,80,40,70,50]
p.line(listx, listy)
show(p)

from bokeh.plotting import figure, show, output_file

output_file("F:\\pythonBase\\pythonex\\lineout.html")
p = figure(width=800, height=400)
listx = [1,5,7,9,13,16]
listy = [15,50,80,40,70,50]
p.line(listx, listy)
show(p)

from bokeh.plotting import figure, show

p = figure(width=800, height=400, title="零花钱统计")
# p.title_text_color = "green"
# p.title_text_font_size = "18pt"
p.xaxis.axis_label = "年龄"
p.xaxis.axis_label_text_color = "violet"
p.yaxis.axis_label = "零花钱"
p.yaxis.axis_label_text_color = "violet"
dashs = [12, 4]
listx1 = [1,5,7,9,13,16]
listy1 = [15,50,80,40,70,50]
p.line(listx1, listy1, line_width=4, line_color="red", line_alpha=0.3, line_dash=dashs, legend="男性")
listx2 = [2,6,8,11,14,16]
listy2 = [10,40,30,50,80,60]
p.line(listx2, listy2, line_width=4, legend="女性")
show(p)

from bokeh.plotting import figure, show

p = figure(width=800, height=400, title="零花钱统计")
# p.title_text_font_size = "18pt"
p.xaxis.axis_label = "X 轴"
p.yaxis.axis_label = "y 轴"
listx = [1,5,7,9,13,16]
listy = [15,50,80,40,70,50]
sizes=[10,20,30,30,20,10]
colors=["red","blue","green","pink","violet","gray"]
#sizes=25 #所有点相同大小
#colors="red" #所有点相同颜色
p.circle(listx, listy, size=sizes, color=colors, alpha=0.5)
show(p)

from bokeh.plotting import figure, show
import matplotlib.pyplot as plt #导入绘图模块,重命名为plt
import requests #导入网页内容抓取包
from bs4 import BeautifulSoup as bs #导入网页解析模块,重命名为bs

year = [] #横坐标列表
gdp = [] #纵坐标列表
url = "http://value500.com/M2GDP.html" #设置要在哪个网页抓数据
content = requests.get(url) #获取网页内容
content.encoding=‘utf-8‘ #转为utf-8编码
content1=content.text #取得网页内容的text部分
parse = bs(content1,"html.parser") #进行html解析
data1 = parse.find_all("table") #获取所有表元素
rows = data1[19].find_all("tr") #取出包含所需数据的表(网页第20个表)
i=0 #为了不读取表头数据,设置此控制变量
for row in rows:
cols = row.find_all("td") #把每一行表数据存入cols变量
if(len(cols) > 0 and i==0): #如果是第一行,则控制变量加1
i+=1
else: #如果不是第一行,则写入绘图列表
year.append(cols[0].text[:-2]) #取得年份数据(数据的最后两个字符不是数据需去除)并写入图形的year轴
gdp.append(cols[2].text) #把gdp值存入gdp轴

p = figure(width=800, height=400, title="1990~2016年度我国GDP") #在浏览器生成画图区域
p.title_text_font_size = "20pt" #设置字体大小为20
p.xaxis.axis_label = "年度" #设置x轴标题
p.yaxis.axis_label = "GDP(亿元)" #设置y轴标题
p.circle(year,gdp, size=6) # 圆点显示,点的大小为6
show(p) #显示图形

原文地址:https://www.cnblogs.com/tszr/p/10061290.html

时间: 2024-08-01 03:13:07

吴裕雄 实战PYTHON编程(6)的相关文章

吴裕雄 实战python编程(3)

import requests from bs4 import BeautifulSoup url = 'http://www.baidu.com'html = requests.get(url)sp = BeautifulSoup(html.text, 'html.parser')print(sp) html_doc = """<html><head><title>页标题</title></head> <p

吴裕雄 实战PYTHON编程(7)

import os from win32com import client word = client.gencache.EnsureDispatch('Word.Application')word.Visible = 1word.DisplayAlerts = 0doc = word.Documents.Add()range1 = doc.Range(0,0) #文件起始处range1.InsertAfter("这是测试第一行\n这是测试第二行\n")range1.InsertAft

吴裕雄 实战PYTHON编程(8)

import pandas as pd df = pd.DataFrame( {"林大明":[65,92,78,83,70], "陈聪明":[90,72,76,93,56], "黄美丽":[81,85,91,89,77], "熊小娟":[79,53,47,94,80] } )print(df) import pandas as pd datas = [[65,92,78,83,70], [90,72,76,93,56], [8

吴裕雄 实战PYTHON编程(9)

import cv2 cv2.namedWindow("ShowImage1")cv2.namedWindow("ShowImage2")image1 = cv2.imread("F:\\pythonBase\pythonex\\ch10\\media\\img01.jpg")#image1 = cv2.imread("media\\img01.jpg", 1)image2 = cv2.imread("F:\\pyt

Python编程实战:运用设计模式、并发和程序库创建高质量程序 阅读笔记

Python编程实战:运用设计模式.并发和程序库创建高质量程序 目录 1 创建型设计模式 2 结构型设计模式 3 行为型设计模式 4 高级并发 5 扩充Python 6 高级网络编程 7 Tkinter 8 OpenGL 创建型设计模式 抽象工厂 @classmethod def make_xxx(Class, ...) Builder with open(filename, "w", encoding='utf-8') as f: f.write(x) 多一层映射封装好吗? 序列与m

树莓派Python编程入门与实战 PDF

树莓派Python编程入门与实战 链接:https://pan.baidu.com/s/1y2-912g7VknVzXKAdzUPpA 密码:rzbz 原文地址:https://www.cnblogs.com/luoshuifusheng/p/9376025.html

从能做什么到如何去做,一文带你快速掌握Python编程基础与实战

摘要:Python语言的教程虽然随处可见,但是忙于日常业务/学习的你或许:一直想要"找个时间学一点",但是又不知道该从何下手?本文将从Python能做什么,如何学习Python以及Python的基础知识为你的Python之路点上一盏明灯. 本文内容根据演讲视频以及PPT整理而成. 本文的分享主要围绕以下几个方面: Python能做什么?(常见应用场景介绍) 如何学习Python? Python语法基础实战 Python面向对象编程实战 练熟基础:2048小游戏项目的实现与实战 福利:小

python经典书籍:Python编程实战 运用设计模式、并发和程序库创建高质量程序

Python编程实战主要关注了四个方面 即:优雅编码设计模式.通过并发和编译后的Python(Cython)使处理速度更快.高层联网和图像.书中展示了在Python中已经过验证有用的设计模式,用专家级的代码阐释了这些设计模式,并解释了为什么一些与面向对象设计相关的模式和Python均有关联. 书中通过大量实用的范例代码和三个完整的案例研究,全面而系统地讲解 了如何运用设计模式来规划代码结构,如何通过 并发与Cython等技术提升代码执行速度,以及如 何利用各科IPython程序库来快速开发具体的

Python编程(二):Python进程、线程那点事儿

多进程,多线程编程 系统程序员.运维开发程序员在面试的时候经常会被问及一个常见问题: 进程是什么,线程是什么,进程和线程有什么区别? 不得不承认,这么多年了.这个问题依旧是个很难以招架的问题,简单地说: 进程和线程有很多类似的性质,他们都可以被CPU作为一个单元进行调度,他们都拥有自己独立的栈(stack)等等.因此线程也被称作LWP(Lightweight Process,轻量级进程):对应的进程也可以被称作为HWP(Heavyweight Process,重量级进程),从线程的角度看,进程就