matplotlib -work4

作业

1.尝试在一张图中运用所讲过的功能,对title、text、xlable、ylabel、数学表达式、tick and ticklabel、legend进行详细的设计.
2.阅读你可能用到文献或者相关书籍,思考自己如何才能通过学过的例子将自己认为比较好看的图给复现出来.

#该block讲述如何在matplotlib里面,修改字体默认属性,完成全局字体的更改。
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimSun']    # 指定默认字体为新宋体。
plt.rcParams['axes.unicode_minus'] = False      # 解决保ds存图像时 负号'-' 显示为方块和报错的问题。
import matplotlib.pyplot as plt
import matplotlib
from matplotlib.font_manager import FontProperties
import numpy as np
x = np.linspace(0,6,100)
y = np.sinc(x)
y2 = 0.05*(x-3)**2

fig = plt.figure()
fig.suptitle('sinc函数')

ax = fig.add_subplot(1,1,1)
font = {'family': 'Times New Roman',
        'color':  'purple',
        'weight': 'normal',
        'size': 15,
        }
ax.set_title('sinc and quadratic',fontdict=font)

ax.plot(x,y,label='sinc')
ax.text(0.2,0.6,r'$\sinc (x)$')
ax.plot([0,6],[0,0],linestyle='dashed',color='gray')
ax.plot(x,y2,label='quadratic')
ax.text(4.5,0.3,r'$0.05 \times (x-3)^2$')
ax.set_xlim(0,6)
ax.set_xlabel('x')
ax.set_ylabel('y')
formatter = matplotlib.ticker.FormatStrFormatter('%1.1f')
ax.xaxis.set_major_formatter(formatter)
locator = matplotlib.ticker.MultipleLocator(2)
ax.xaxis.set_major_locator(locator)

ax.legend(loc = 'upper center')
<matplotlib.legend.Legend at 0x2c392cb08b0>

在这里插入图片描述

  1. 需要拟合时的数据准确,选择适当的坐标设置,并且对于不同子图的间距以及大小相应调整,根据图像的样式判断选择何种工具来实现。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值