用python实现自动化办公代码

大家好,小编来为大家解答以下问题,如何利用python进行自动化办公? 用python自动化办公 做职场高手,现在让我们一起来看看吧!

1 基本图形

1.1 折线图

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['-serif'] = ["SimHei"]
x = [x for x in range(0, 11)]
y1 = [2,5,3,6,4,6,9,22,13,14,14] #疫情前
y2 = [4,4,6,5,6,8,9,20,11,19,9]
y3 = [4,5,3,5,3,7,10,18,11,21,13]
labels = ['非常不需要', '1', '2', '3', '4', '5', '6', '7', '8', '9', '非常需要']
ax1 = plt.subplot(111)
(labels, y1, 'm--o',  label='不同餐饮企业之间合作',color = '#00008B')
(x, y2, 'g--o',  label='餐饮与其他非餐饮品牌联名',color = '#87CEFA')
(x, y3, 'b--o',  label='餐饮与当地文化结合',color = '#98FB98')
ax1.set_title("用户对餐饮企业合作及文化融合的看法", fontsize=11)

ax1.set_ylim(0, 25)
ax1.set_ylabel('百分比(%)')
# ax1.set_xlabel('')

for xy1 in zip(x, y1):  # text()会将文本放置在轴域的任意位置使用phpStudy搭建服务器的深度探讨。 文本的一个常见用例是标注绘图的某些特征,而annotate()方法提供辅助函数,使标注变得容易
    ax1.annotate("%s" % xy1[1], xy=xy1, xytext=(-5, 5), textcoords='offset points')
# "%s" % xy1[1]输出字符串!
for xy2 in zip(x, y2):
    ax1.annotate("%s" % xy2[1], xy=xy2, xytext=(-5, 5), textcoords='offset points')
for xy3 in zip(x, y3):
    ax1.annotate("%s" % xy3[1], xy=xy3, xytext=(-5, 5), textcoords='offset points')

ax1.legend()
# ax2 = plt.subplot(223)
# (y1, radius=1, wedgeprops={'width': 0.5}, labels=labels, autopct='%3.1f%%', pctdistance=0.75)
# ax2.set_title('产品A的销售额 ')
# ax3 = plt.subplot(224)
# (y2, radius=1, wedgeprops={'width': 0.5}, labels=labels, autopct='%3.1f%%', pctdistance=0.75)
# ax3.set_title('产品B的销售额 ')
# plt.tight_layout()
()

1.2 柱形图或堆积柱形图

x = np.arange(5)
y1 = np.array([10,8,7,11,13])
plt.title("呵呵013")
bar_width = 0.3
(x,y1,tick_label=['a','b','c','d','e'],width=bar_width)
()

x = np.arange(5)
y1 = np.array([9,4,6,8,10])
y2 = np.array([10,8,7,11,13])
plt.title("呵呵013")
bar_width = 0.3
(x,y1,tick_label=['a','b','c','d','e'],width=bar_width)
(x+bar_width,y2,width=bar_width)
()

# 实例9某地区全年平均气温降水量、蒸发量的关系
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
month_x = np.arange(1, 6, 1)

# 疫情前
data_precipitation = np.array([16.67,38.89,18.52,18.52,7.41])
# 疫情后
data_evaporation = np.array([8.52,12.22,20.74,40.00,18.52])
fig, ax = plt.subplots()
bar_ev = (month_x, data_precipitation, color='#87CEFA', tick_label=['从不前往','2','3','4','总去餐厅'],width = 0.4)
bar_pre = (month_x, data_evaporation, bottom=data_precipitation, color='#00008B',width=0.4)
_ylabel('百分比(%)')
_title('疫情放开前后去餐厅频率变化对比图')
# ax_right = ax.twinx()
# ax_right.set_ylabel('气温($^\circ$C)')
# 添加图例
plt.legend([bar_ev, bar_pre], ['疫情放开前', '疫情放开后'],
           shadow=True, fancybox=True)
()

import matplotlib.pyplot as plt
import pandas as pd
import cmaps
import seaborn as sns
# 获取'人均GDP(元)'这一列的值
y = [16.95,22.03,23.73,37.29]
y = sorted(y)
# 获取索引列的值(年份)
# x =['18-22岁',,'25-35岁','35-45岁','45-55岁','55岁以上']
x = ['多于3000元','少于1000元','2000-3000元','1000-2000元']
# 指定默认字体(防止中文出现乱码)
from pylab import mpl

plt.rcParams["-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False

fig, ax = plt.subplots()
new_blues = sns.color_palette("GnBu", 20)[8:16]
bar_ev = (x, y, color=new_blues,width=0.4)
# bar_pre = (month_x, data_evaporation, bottom=data_precipitation, color='green')
_ylabel('百分比(%)')
_title('未就业人群的月生活费水平分布图')
_ylim(0,40)

for xy1 in zip(x, y):  # text()会将文本放置在轴域的任意位置。 文本的一个常见用例是标注绘图的某些特征,而annotate()方法提供辅助函数,使标注变得容易
    ax.annotate("%s" % xy1[1], xy=(xy1[0],xy1[1]), xytext=(-5, 5), textcoords='offset points')

()
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["axes.unicode_minus"] = False
plt.rcParams["-serif"] = ["SimHei"]
n = 5
X = np.arange(1,n+1)

Y1 = np.array([4.44, 12.96, 8.52, 7.78, 12.59])
Y2 = np.array([-8.89,-10.37,-13.7,-8.89,-5.93])
(X,+Y1,facecolor='#00008B',edgecolor='white',label ='到店就餐',width=0.6)# +:向上
(X,Y2,facecolor='#87CEFA',edgecolor='white',label = '线上团购点餐',width=0.6)# -:向下
for x,y in zip(X,Y1): # zip:X和 Y1 分别赋值给x,y
    (x,y,'%.2f' % y,ha='center',va='bottom') # ha:horizontal alignment 横向对齐方式,va纵向对其方式

for x,y in zip(X,Y2): # zip:X和 Y2 分别赋值给x,y
    (x,y+.15,'%.2f' % -y,ha='center',va='bottom') # ha:horizontal alignment 横向对齐方式

plt.legend()
(0.5,n+1)
# plt.xticks(())
(-15,15)
# plt.yticks(())
plt.ylabel("百分比(%)")
plt.xlabel("喜爱程度")
plt.title("到店点餐和线上团购点餐对比图")

()

1.3 条形图

y = np.arange(5)
x1 = np.array([10,8,7,11,13])
plt.title("呵呵013")
bar_height = 0.3
(y,x1,tick_label=['a','b','c','d','e'],height=bar_height)
()

y = np.arange(5)
x1 = np.array([10,8,7,11,13])
x2 = np.array([9,4,6,8,10])
plt.title("呵呵013")
bar_height = 0.3
(y,x1,tick_label=['a','b','c','d','e'],height=bar_height)
(y+bar_height,x2,height=bar_height)
()

y = np.arange(5)
x1 = np.array([10,8,7,11,13])
x2 = np.array([9,4,6,8,10])
plt.title("呵呵013")
bar_height = 0.3
(y,x1,tick_label=['a','b','c','d','e'],height=bar_height)
(y,x2,left=x1,height=bar_height)
()

1.3.1 当左边的label名太长没有办法完全显示时:
import matplotlib.pyplot as plt
from math import pi
import numpy as np
from matplotlib.patches import Patch

plt.rcParams['-serif'] = ["SimHei"]
y = np.arange(5)
x1 = np.array([10, 8, 7, 11, 13])
plt.title("呵呵013")
bar_height = 0.3
(y, x1, tick_label=['订购外卖无需排队节约时间', '外卖有优惠折扣价格平易近人', '外卖平台服务态度良好', '自身烹饪水平有限', '其他'], height=bar_height)
# 设置tight bbox


plt.savefig("", bbox_inches='tight')
()

只需要在plt.savefig时加入参数bbox_inches='tight'即可!!!

1.3.2 条形图上显示数字
import matplotlib.pyplot as plt
from math import pi
import numpy as np
from matplotlib.patches import Patch
import seaborn as sns
plt.rcParams['-serif'] = ["SimHei"]
y = np.arange(5)
x1 = np.array([70, 63, 44, 29.5, 0.5])

# sns.palplot(sns.color_palette("GnBu", 30))
#
# sns.palplot(sns.color_palette("GnBu", 30)[10:1:-1])
new_blues = sns.color_palette("GnBu", 20)[10:1:-1]
colors = new_blues
bar_height = 0.5
(0,90)
plt.title("消费者订外卖意愿度高原因分析图")
plt.xlabel("百分比(%)")
# plt.ylabel()
(y, x1, tick_label=['订购外卖无需排队节约时间', '外卖有优惠折扣价格平易近人', '外卖平台服务态度良好', '自身烹饪水平有限', '其他'], height=bar_height,color=colors)
# 设置tight bbox

for x, y in enumerate(x1):
    (y + 0.2, x - 0.1, '%s' % y)
plt.savefig("", bbox_inches='tight')
()

1.4 饼图

import matplotlib.pyplot as plt
import pandas as pd
import cmaps
import seaborn as sns
# 获取'人均GDP(元)'这一列的值
y = [0.0704,0.3037,0.2815,0.1926,0.1111,0.0407]
y = sorted(y)
# 获取索引列的值(年份)
# x =['18-22岁',,'25-35岁','35-45岁','45-55岁','55岁以上']
x = ['55岁以上','18-22岁','45-55岁','35-45岁','25-35岁','22-25岁']
# 指定默认字体(防止中文出现乱码)
from pylab import mpl

plt.rcParams["-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
# sns.palplot(sns.color_palette("GnBu", 30))
#
# sns.palplot(sns.color_palette("GnBu", 10)[2:9])

new_blues = ["orange"]+sns.color_palette("GnBu", 10)[2:7]
# 饼状图
fig, ax = plt.subplots()
(y, labels=x,colors=new_blues,autopct='%3.2lf%%',)
plt.title('问卷调查年龄分布情况')
()

1.5 散点图

# 数据读入
scatter_df = pd.read_csv('', index_col='分行编号')
 
x = scatter_df['各项贷款余额']
y = scatter_df['不良贷款(亿元)']
 
# 指定默认字体(防止中文出现乱码)
from pylab import mpl
mpl.rcParams['-serif'] = ['FangSong']  # 指定‘仿宋’字体
 
# 散点图
fig, ax = plt.subplots()
ax.scatter(x, y, alpha=0.5)  # alpha是设置透明度,这样点重合时看的明显
 
# 设置标题,标签
(title='散点图', xlabel='各项贷款余额',ylabel='不良贷款(亿元)')
 
# 显示图形
()

1.6 堆积面积图

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(1,13)
y_a = np.array([198,215,245,222,200,236,201,253,236,200,266,290])
y_b = np.array([203,236,200,236,269,216,298,333,301,349,360,368])
y_c = np.array([185,205,226,199,238,200,250,209,246,219,253,288])
# 绘制堆积面积图
plt.stackplot(x,y_a,y_b,y_c)
()

1.7 直方图(连续的数,分组)

hist参数绘制直方图 该函数常用参数的含义如下。

x:表示x轴的数据,可以为单个数组或多个数组的序列 bins:表示矩形条的个数,默认为10 range:表示数据的范围,若没有提供range参数,则数据范围为(x.min(),x.max()) cumulative:表示是否计算累积频数或频率 histtype:表示直方图的类型,支持’bar’,‘barstacked’,‘step’,‘stepfilled’四种取值,其中’bar’为默认值,代表传统的直方图;‘barstacked’代表堆积直方图,’'step’代表未填充的线条直方图;'stepfilled’代表填充的线条直方图 align:表示矩形条边界的对齐方式,可设置为’left’,‘mid’,‘right’默认为’mid’, orientation:表示矩形条的摆放方式,默认为’vertical’,即垂直方向 rwidth:表示矩形条宽度的百分比,默认为0.若histtype的值为’step’或’stepfilled’,则直接忽略rwidth参数的值 stacked:表示是否将多个矩形条以堆积形式摆放  

import numpy as np
import matplotlib.pyplot as plt
scores = np.random.randint(0,100,50)
# 绘制直方图
(scores,bins=8,histtype='stepfilled')
()

1.8 箱线图

import matplotlib.pyplot as plt
# 生成数据
x = [-10, -3, -2, -1, 0, 1, 2, 3, 10]
plt.boxplot(x)
()

1.9 雷达图

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
dim_num = 6
data = np.array([[0.40,0.32,0.35,0.30,0.30,0.88],
                 [0.85,0.35,0.30,0.40,0.40,0.30],
                 [0.43,0.59,0.30,0.28,0.22,0.30],
                 [0.30,0.25,0.48,0.85,0.45,0.40],
                 [0.20,0.38,0.87,0.45,0.32,0.28],
                 [0.34,0.31,0.38,0.40,0.92,0.28]])
angles = np.linspace(0,2*,dim_num,endpoint=False)
angles = np.concatenate((angles,[angles[0]]))
data = np.concatenate((data,[data[0]]))
# 维度标签
rrandar_labels = ['研究型(I)', '艺术型(A)', '社会型(S)', '企业型(E)', '传统型(C)', '现实型(R)']
radar_labels= np.concatenate((rrandar_labels,[rrandar_labels[0]]))
# 绘制雷达图
plt.polar(angles,data)
# 设置极坐标的标签
plt.thetagrids(angles*,labels=radar_labels)
# 填充多边形
(angles,data,alpha=0.25)
()


1.10 圆环进度条


import matplotlib.pyplot as plt
from math import pi
import numpy as np
from matplotlib.patches import Patch
from matplotlib.lines import Line2D
import seaborn as sns
plt.rcParams['-serif'] = ["SimHei"]
fig, ax = plt.subplots(figsize=(8, 8))
ax = plt.subplot(projection='polar')
data = [17.14,28.57,52.86,57.14,60]
startangle = 90
# sns.palplot(sns.color_palette("GnBu", 30))
#
# sns.palplot(sns.color_palette("GnBu", 10)[2:9])

new_blues = sns.color_palette("GnBu", 10)[2:9]
colors = new_blues
# colors = ['#4393E5', '#43BAE5', '#7AE6EA']
xs = [(i * pi * 2) / 100 for i in data]
ys = [-1.4,-0.2, 1, 2.2,3.4]
left = (startangle * pi * 2) / 360  # this is to control where the bar starts
# plot bars and points at the end to make them round
for i, x in enumerate(xs):
    (ys[i], x, left=left, height=1, color=colors[i])
    ax.scatter(x + left, ys[i], s=350, color=colors[i], zorder=2)
    ax.scatter(left, ys[i], s=350, color=colors[i], zorder=2)

(-4, 4)
# legend
legend_elements = [Line2D([0], [0], marker='o', color='w', label='外卖配送时间长', markerfacecolor=colors[0] , markersize=10),
                   Line2D([0], [0], marker='o', color='w', label='喜欢自己做饭', markerfacecolor=colors[1], markersize=10),
                   Line2D([0], [0], marker='o', color='w', label='外卖费用高', markerfacecolor=colors[2], markersize=10),
                   Line2D([0], [0], marker='o', color='w', label='担心外卖卫生质量', markerfacecolor=colors[2], markersize=10),
                   Line2D([0], [0], marker='o', color='w', label='喜欢餐厅就餐', markerfacecolor=colors[2], markersize=10)
]
ax.legend(handles=legend_elements, loc='center', frameon=False)
# clear ticks, grids, spines
plt.xticks([])
plt.yticks([])
ax.spines.clear()
plt.title("消费者从不订购外卖或者较少订购外卖的原因分析")
()

2 辅助元素定制

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
x = np.linspace(,,256,endpoint=True)
y1, y2 = (x),(x)
(x,y1,x,y2)
plt.xlabel("x轴")
plt.ylabel("y轴")
plt.title('2020080603042')
()

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
x = np.linspace(,,256,endpoint=True)
y1, y2 = (x),(x)
lines = (x,y1,x,y2)
plt.axvline(x=0,linestyle='--')
plt.axhline(y=0,linestyle='--')
plt.legend(lines, ['正弦','余弦'],shadow=True,fancybox=True)
(x,y1,x,y2)
plt.xlabel("x轴")
plt.ylabel("y轴")
(b=True,axis='y',linewidth=1.3)
(x.min() *1.5, x.max() *1.5)
plt.xticks([, , 0, , ], [r'$-\pi$',r'$-\pi/2$',r'$0$',r'$-\pi/2$',r'$-\pi$',])
plt.axvspan(xmin=0.5,xmax=2.0,alpha=0.3)
plt.axhspan(ymin=0.5,ymax=1.0,alpha=0.3)
plt.annotate("最小值",xy=( / 2, -1.0),
            xytext=(-( / 2), -0.5),
            arrowprops=dict(arrowstyle="->"))
plt.title('2020080603042')
(3.10,0.10,"y=sin(x)",bbox=dict(alpha=0.2))
plt.table(cellText=[[6,6,6,],[8,8,8]],
         colWidths=[0.1]*3,
         rowLabels=['第一行','第二行'],
         colLabels=['第一行','第二行','第三行'],loc='lower right')
()

import matplotlib.pyplot as plt
plt.rcParams['-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
labels=["哪吒之魔童降世","流浪地球",
        "复仇者联盟4:终局之战","疯狂外星人",
        "飞驰人生","烈火英雄","蜘蛛侠:英雄远征",
        "速度与激情:特别行动","扫毒2:天地对决","大黄蜂",
        "惊奇队长","比悲伤更悲伤的故事","哥斯拉2:怪兽之王",
        "阿丽塔:战斗天使","银河补习班"]
bar_width=[48.57,46.18,42.05,21.83,16.70,14.01,13.81,
           12.98,11.89,10.25,9.46,9.27,8.88,8.64,8.20]
y_data=range(len(labels))
fig=plt.figure()
ax=fig.add_subplot(111)
(y_data,bar_width,height=0.2,color='pink')
_xlabel("总票房(亿元)")
_ylabel("电影名称")
_yticks(y_data)
_yticklabels(labels)
plt.title('2020080603042')
()

import matplotlib.pyplot as plt
plt.rcParams['-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
kinds=['购物','人情往来','餐饮美食','通信物流','生活日用','交通出行','休闲娱乐','其他']
money_scale=[800/3000,100/3000,1000/3000,300/3000,
200/3000,200/3000,200/3000,200/3000]
dev_position=[0.1,0.1,0.3,0.1,0.1,0.1,0.1,0.1]
(money_scale,labels=kinds,autopct='%%',
shadow=True,explode=dev_position,startangle=90)#逆时针开始绘制90度
plt.title('2020080603042')
plt.legend(kinds,loc='upper right',bbox_to_anchor=[1.3,1.1])
()

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
men_means=(90.5,89.6,88.7,88.6,86.5,84.6)
women_means=(92.8,87.0,90.5,85.4,89.6,90.2)
ind=np.arange(len(men_means))
width=0.2
fig=plt.figure()
ax=fig.add_subplot(111)
(ind-width/2,men_means,width,label='男生平均成绩')
(ind+0.2,women_means,width,label='女生平均成绩')
_title('高二各班男生、女生英语平均成绩')
_ylabel('分数')
_xticks(ind)
_xticklabels(['高二1班','高二2班','高三3班','高三4班','高三5班','高三6班'])
ax.axhline(88.5,ls='--',linewidth=1.0,label='全体平均成绩')
ax.legend(loc="lower right")
plt.title('2020080603042')
()

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
x=np.arange(1,8)
y=np.array([10770,16780,24440,30920,37670,48200,57270])
(x,y,tick_label=["FY2013","FY2014","FY2015","FY2016","FY2017","FY2018","FY2019"],width=0.5)
def autolabel(rects):
    for rect in rects:
        height=rect.get_height()
        (rect.get_x()+rect.get_width()/2,height+300,s='{}'.format(height),ha='center',va='bottom')
autolabel(bar_rects)
plt.ylabel('GMV(亿元)')
plt.title('2020080603042')
()

3 图标样式的美化

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["-serif"]=["SimHei"]
plt.rcParams["axes.unicode_minus"]=False
x=np.arange(5)
y1=[1200,2400,1800,2200,1600]
y2=[1050,2100,1300,1600,1340]
bar_width=0.6
tick_label=['家庭',"小说","心理","科技","儿童"]
fig=plt.figure()
ax=fig.add_subplot(111)
(x,y1,bar_width,color="#FFCC00",align="center",label="地区1")
(x,y2,bar_width,bottom=y1,color="#B0C4DE",align="center",label="地区2")
_ylabel("采购数量(本)")
_xlabel("图书种类")
_title("地区1和地区2对各类图书的采集情况")
(True,axis='y',color="gray",alpha=0.2)
_xticks(x)
_xticklabels(tick_label)
ax.legend()
plt.title("2020080603042")
()

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["-serif"]=["SimHei"]
plt.rcParams["axes.unicode_minus"]=False
eurcny_2017=np.array([6.8007,6.8007,6.8015,6.8060,6.8060,
                      6.8060,6.8060,6.8036,6.8077,6.7877,
                      6.8035,6.7758,6.7700,6.7463,6.7519,
                      6.7511,6.7511,6.7539,6.7265])
eurcny_2019=np.array([6.8640,6.8705,6.8679,6.8679,6.8697,
                     6.8881,6.8853,6.8856,6.8677,6.8662,
                     6.8662,6.8662,6.8827,6.8761,6.8635,
                     6.8860,6.8737,6.8796,6.8841])
date_x=np.array([3,4,5,6,7,8,9,10,
                 11,12,13,14,17,18,
                 19,24,25,26,31])
fig=plt.figure()
ax=fig.add_subplot(111)
(date_x,eurcny_2017,color='#006374',linewidth=2,label='2017年7月美元/人民币汇率')
(date_x,eurcny_2019,color='#8a2e76',linestyle='--',linewidth=2,label='2019年7月美元/人民币汇率')
_title('2017年7月与2019年7月美元/人民币汇率走势')
_xlabel('日期')
_ylabel('汇率')
ax.legend()
plt.title("2020080603042")
()

([1,2,3],[3,4,5],marker='*',markersize=20,markerfacecolor='#FF6900')

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["-serif"]=["SimHei"]
plt.rcParams["axes.unicode_minus"]=False
sale_a=[2144,4617,7674,6666]
sale_b=[853,1214,2414,4409]
sale_c=[153,155,292,680]
fig=plt.figure()
ax=fig.add_subplot(111)
(sale_a,'s-',sale_b,'^:',sale_c,'s--')
(alpha=0.3)
_ylabel('销售额(万元)')
_xticks(np.arange(len(sale_c)))
_xticklabels(['第一季度','第二季度','第三季度','第四季度'])
ax.legend(['产品A','产品B','产品C'])
plt.title("2020080603042")
()

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["-serif"]=["SimHei"]
plt.rcParams["axes.unicode_minus"]=False
x=np.arange(4,19)
y_max=[32,33,34,33,31,30,29,30,29,26,23,21,25,31,32]
y_min=[19,19,18,17,19,20,21,22,16,17,15,14,16,15,16]
(x,y_max,marker='o',label='最高温度')
(x,y_min,marker='o',label='最低温度')
x_temp=4
for y_h,y_1 in zip(y_max,y_min):
    (x_temp-0.3,y_h+0.7,y_h,family='SimHei',fontsize=8,fontstyle='normal')
    (x_temp-0.3,y_1+0.7,y_1,family='SimHei',fontsize=8,fontstyle='normal')
    x_temp+=1
plt.title('未来15天最高气温和最低气温的走势2020080603042')
plt.xlabel('日期')
plt.ylabel('温度($^\circ$C)')
(0,40)
plt.legend()
()

import numpy as np 
import matplotlib.pyplot as plt
x=np.linspace(0,8*,1000)
(x)
(1.5*)/2
(x,sin_y)
(x,cos_y)
_between(x,cos_y,sin_y,cos_y<sin_y,color='#00FF11',alpha=1)
_between(x,cos_y,sin_y,cos_y>sin_y,color='#FFE400',alpha=1)

import numpy as np
import matplotlib.pyplot as plt
def koch_snowflake(order,scale=10):
    def _koch_snowflake_complex(order):
        if order==0:
            angles=np.array([0,120,240])+90
            return (3)*(np.deg2rad(angles)*1j)
        else:
            ZR=0.5-0.5j*(3)/3
            p1 = _koch_snowflake_complex(order-1)
            p2 = (p1,shift=-1)
            dp = p2-p1
            new_points=np.empty(len(p1)*4,dtype=np.complex128)
            new_points[::4]=p1
            new_points[1::4]=p1+dp/3
            new_points[2::4]=p1+dp*ZR
            new_points[3::4]=p1+dp/3*2
            return new_points
    points=_koch_snowflake_complex(order)
    x,,
    return x,y
x,y=koch_snowflake(order=2)
fig=plt.figure()
ax=fig.add_subplot(111)
(x,y,facecolor='lightsalmon',edgecolor='orangered',linewidth=3)
plt.title('2020080603042')
()

4 子图的绘制及坐标的共享

Python数据可视化(5):子图的绘制及坐标轴的共享_python子图-CSDN博客

5 颜色

5.1 个性化颜色

单个颜色使用:

渐变颜色: 

seaborn可通过设置cmap参数来选择色集绘制图表,例如我现在使用的是蓝色色集

sns.heatmap(dfData, annot=True, vmax=1, square=True, cmap="Blues")

系统自带的色集有很多!

对于颜色的三种模式,我们在使用colormap时,可以使用camp参数设置相应颜色的图,关于camp参数的的设置如下: 视觉上均匀的连续型:

连续型的:

极端型的: 离散型的: 混合型的:

自定义的话:

你这个蓝色渐变颜色最深的地方都成黑色了,能不能不要那么深,从浅蓝到深蓝就可以了

这时我们就要在原有的色集上修改

sns.palplot(sns.color_palette("Blues", 10)) 

首先用sns.color_palette将‘Blues’色集按照纯度将其10等分,sns.palplot()可以将色集打印出来

new_blues=sns.color_palette("Blues", 10)[0:7]

在画图的时候直接使用新的色集‘new_blues’就可以了

 sns.heatmap(dfData, annot=True, vmax=1, square=True, cmap=new_blues)

如果觉得颜色不够细腻的话就将10改为1000将其1000等分后取前700

new_blues=sns.color_palette("Blues", 1000)[0:700]

5.2 实例

5.2.1 示例1

完整代码

import pandas as pd
import numpy as np
%matplotlib inline
df1=pd.read_csv("")

sns.palplot(sns.color_palette("Blues", 10))

sns.palplot(sns.color_palette("Blues", 10)[0:7])

new_blues=sns.color_palette("Blues", 10)[0:7]


import seaborn as sns
import matplotlib.pyplot as plt
(font='SimHei',font_scale=2)
def test_b(df):
    dfData = ()
    plt.subplots(figsize=(15, 15)) # 设置画面大小
    sns.heatmap(dfData, annot=True, vmax=1, square=True, cmap=new_blues)
    
    plt.savefig('')
    ()
test_b(df1)
5.2.2 示例2
# 实例9某地区全年平均气温降水量、蒸发量的关系
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams["-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
month_x = ['关闭或转型','2','3','4','5','6','7','8','9','生意兴隆']

x = [x for x in range(0, 10)]

data_precipitation = np.array([3,2,3,6,6,17,19,13,20,10])
fig, ax = plt.subplots()
new_blues = sns.color_palette("GnBu", 20)[6:16]
bar_ev = (month_x, data_precipitation, color=new_blues,width=0.6)
_ylabel('百分比(%)')
_title('疫情对“老字号”餐饮企业的影响图')


for xy1 in zip(x, data_precipitation):  # text()会将文本放置在轴域的任意位置。 文本的一个常见用例是标注绘图的某些特征,而annotate()方法提供辅助函数,使标注变得容易
    ax.annotate("%s" % xy1[1], xy=xy1, xytext=(-5, 5), textcoords='offset points')

()


原文地址1:https://blog.csdn.net/qq_64279967/article/details/137432531
参考资料:python中用turtle画一个圆形 https://blog.csdn.net/SXIAOYAN_/article/details/140061099

  • 30
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值