使用plt库绘制图标

使用Python中的plt库来绘制图表

观前提示以下所有代码都是在Jupyter notebook上,学会运用kupyter notebook后发现它真的十分好用,所以可能放在sublime会出点问题(别问我为什么知道)

#1 简单的绘制两个函数的图像

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-10,10,100)#通过调用numpy库的linspaces来随机生成100个数

y = 4/x+1
g = x3-4*x2+2*x+7
plt.plot(x,y)
plt.plot(x,g)#直接显示函数
plt.plot(x,y,label=‘y=4/x+1’)#对函数加以注释
plt.plot(x,g,label=‘y=x3-4x2+2x+7’)
plt.xlabel(“I’m your boyfirend,”)#皮一下
plt.ylabel(“I’am your girlfriend”)#分别对x和y轴加以注释(醒醒,我怎么可能有女朋友)
plt.title(“I’m a handsome boy”)整个图表的标题
plt.plot(x,g,color=‘yellow’,linewidth=3,linestyle=’–’)
plt.plot(x,y,color=‘red’,linewidth=4,linestyle=’-’)

plt.legend() # 用于显示标记,不加的话之前的标记显示不出来
plt.show()
在这里插入图片描述

#折线图

import numpy as np
import matplotlib.pyplot as plt
y1=[5,2,7,3,1,4,5,6,8,9,7,4,15]
x1=range(0 ,13)#x的数量要与y的数量一致否则会报错
x2=range(0 ,13)
#plt.plot(x1,y1,label=‘xxx’,linewidth=2,color=‘gary’,marker=’^’,markerfacecolor=‘blue’,maeksize=19)
y2=[9,25,36,15,5,6,18,9,7,4,15,5,4]
plt.plot(x1,y1,label=‘sd’)
#plt.plot(x2,y2,label=‘op’)
plt.plot(x1,y2,label=‘op’)
plt.legend()
在这里插入图片描述
#转回正题,本次的作业

y=[20,30,15,35]
x=[i1.15-0.15 for i in range(len(y))]
rects1 = plt.bar(x, y, width=0.3, label=“1”)
y2=[15.0,30.0,40.0,20.0]
x2=[i
1.15+0.15 for i in range(len(y))]#经过不断调节这是最好的偏差值,级当偏差值为width的一半时效果最好
rects2=plt.bar(x2,y2, width=0.3,label=“2”)
plt.xlabel(“what!”)
plt.ylabel(“why?”)
plt.title(“nb”)
labels=[‘1’,‘2’,‘3’,‘4’]
plt.xticks(x, labels)
for rect in rects1:
height=rect.get_height()
plt.text(rect.get_x()+rect.get_width()/2,height,str(height), ha=“center”, va=“bottom”)
for rect in rects2:
height=rect.get_height()
plt.text(rect.get_x()+rect.get_width()/2,height,str(height), ha=“center”, va=“bottom”)

#个人认为rects是存储着所有我要输出的每个柱状图的各个参数,这在我使用print(rects)的时候得到证实

plt.legend()
plt.show()

输出结果:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eq6C8JlA-1574488393097)(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAX4AAAEWCAYAAABhffzLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAcRUlEQVR4nO3dfXRV9Z3v8ffXBIm3oIAGGjxwQ00WK2AxYACnWi9gc0HKwFS4iOOtsWBpq64q6hX6pNB1W7A+z5VVS0enGcch7dgK1IcoNjI+tJiGEh0enEkt6eXEKOGpwh2BEL/3j3PAmAc4kLPPTrI/r7WyOHufffb+5HDyyc7v7LO3uTsiIhIdZ4QdQEREMkvFLyISMSp+EZGIUfGLiESMil9EJGJU/CIiEaPiF+kCM5tkZvGwc4icChW/iEjEqPhFRCJGxS+SAjOrN7M7zOwtM/uLmf3czHJa3f9tM9udXO7aMLOKnIyKXyR1c4FpwAhgDHB9cv6ngfOA84EyYJWZjQwjoEgqVPwiqfs7d3/X3fcCvwaKW933PXc/7O7/CjxL4peESLek4hdJ3Xutbv8n0C95e5+7/79W9/0ZGJqxVCKnSMUv0nUDzexTraaHA++GFUbkZFT8IumxzMzONLPPAzOAfwk7kEhnssMOINILvAfsI7GX/5/A19397XAjiXTOdCEWEZFo0VCPiEjEqPhFRCJGxS8iEjEqfhGRiOkRR/Wcd955np+fH3YMEZEeZdOmTbvdPbft/B5R/Pn5+d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5GOvAMcKugTolzzX0GXAq8CngI3Jc+C/Anw1uexrwCXuPpbE+V3udPd64FHgQXcvdvdXM/dtiJxYdtgBRLqRTcDFZtafxIVO/kDiF8DngW8CR4BnWi1bmrwdA35uZnnAmcCOTIYWOVXa4xdJcvdmoB74CvBbEnv5k4ELSFxEptk/PsdJCx/vOP0f4BF3/yzwNSDnBNvoF0h4kVOg4hf5pFeAO5L/vkpinL7WT3xSq3OAhuTtslbzDwD9gwgp0hUqfpFPepXEmS9/5+7vA4eS805kKfAvZvYqsLvV/F8DX2r95q6Z/Tb9kUVOjc7OKSISMdrjFxGJGBW/iEjEqPhFRCJGxS8iEjEqfhGRiFHxi4hEjIpfRCRi/j/keO8Fo76qoQAAAABJRU5ErkJggg==)]

你以为这就完了吗?不不不当我上网搜寻的时候我发现一个个更好的东西

在图表中一旦引入中文最终并不会显示,二是会被一堆方框所掩盖(这怎么行一张图表里没有中文,就仿佛吃方便面没有热水)

所以我最终找到了解决办法

引入下面的模块即可解决

from matplotlib import font_manager

当然他还能做到更多(下面这个程序是我参考别人的打出来的,可能跟别人有些雷同,参考者就把他当一个参考看就好了)

先看下结果:
在这里插入图片描述

from matplotlib import pyplot as plt
from matplotlib import font_manager

my_font = font_manager.FontProperties(fname=“C:/Windows/Fonts/simsun.ttc”)

a = [“无名之辈”, “狗十三”, “毒液:致命守护者”, “憨豆特工3”]
b_7 = [991.94, 375.64, 200.48, 73.27]
b_8 = [1908.22, 547.61, 466.23, 193.8]
b_9 = [1532.87, 525.63, 332.35, 170.57]

b = b_7 + b_8 + b_9
y_1 = []
y_2 = []
y_3 = []
y_4 = []
for i in range(len(b)):
if i % 4 == 0:
y_1.append(b[i])
elif i % 4 == 1:
y_2.append(b[i])
elif i % 4 == 2:
y_3.append(b[i])
else:
y_4.append(b[i])

bar_width = 0.2
x_1 = [i for i in range(3)]
x_2 = [i+bar_width for i in x_1]
x_3 = [i+bar_width2 for i in x_1]
x_4 = [i+bar_width
3 for i in x_1]

plt.figure(figsize=(20, 8), dpi=80)

plt.bar(x_1, y_1, width=bar_width, label=“天气之子”, color=‘red’)
plt.bar(x_2, y_2, width=bar_width, label=“霹雳娇娃”, color=‘blue’)
plt.bar(x_3, y_3, width=bar_width, label=“海上钢琴师”, color=‘yellow’)
plt.bar(x_4, y_4, width=bar_width, label=“终结者”, color=‘gray’)

plt.legend(prop=my_font, loc=5)

#调整x和y的刻度
x_tick = [i+0.1 for i in x_2]
xtick_label = [‘12月7日’, ‘12月8日’, ‘12月9日’]
plt.xticks(x_tick, xtick_label, fontproperties=my_font, fontsize=15)
plt.yticks(fontsize=15)

)
plt.ylabel(“票房(亿元)”, fontproperties=my_font, fontsize=20)
plt.title(“电影票房”, fontproperties=my_font, fontsize=20)

plt.grid(alpha=0.3)

xa = x_1 + x_2 + x_3 + x_4
yb = y_1 + y_2 + y_3 + y_4
for a1, b1 in zip(xa, yb):
plt.text(a1, b1, b1, ha=‘center’, va=‘bottom’, fontsize=14)

plt.savefig(‘T2.png’)
plt.show()

#4 其他的图写完,我这博客会不会太长,算了不管了

饼图

import numpy as np
import matplotlib.pyplot as plt
labels=‘one’,‘two’,‘three’,‘four’
sizes=[50,10,20,20]
explode=(0, 0.1, 0,0)
fig1, ax1 = plt.subplots()
ax1.pie(sizes,labels=labels,autopct=’%1.0f%%’,startangle=10)
ax1.axis(‘equal’)#这个模块是ax 1(数字1)
plt.show()

在这里插入图片描述

#散点图(这个最简单,代码量少)

a=np.random.random(50)
v=np.random.random(50)
colors=np.random.random(50)#随机颜色
area=(100*np.random.random(50))#图表区域面积
plt.scatter(a,v)#生成散点类型
plt.show()

)
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值