注解--python库--matplotlib
生活随笔
收集整理的這篇文章主要介紹了
注解--python库--matplotlib
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
import matplotlib.pyplot as plt import numpy as npx = np.linspace(-3, 3, 50) y = 2*x + 1plt.figure(num=1, figsize=(8, 5),) plt.plot(x, y,)ax = plt.gca() ax.spines['right'].set_color('none')#右邊框?yàn)榭?ax.spines['top'].set_color('none')#上邊框?yàn)榭?ax.xaxis.set_ticks_position('bottom')#設(shè)置下邊為x軸 ax.spines['bottom'].set_position(('data', 0))#設(shè)置下邊即x軸的起始點(diǎn) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data', 0))x0 = 1 y0 = 2*x0 + 1 plt.plot([x0, x0,], [0, y0,], 'k--', linewidth=2.5)#設(shè)置畫該函數(shù)的線的類型和寬度 # set dot styles plt.scatter([x0, ], [y0, ], s=50, color='b')plt.annotate(r'$2x+1=%s$' % y0, xy=(x0, y0), xycoords='data', xytext=(+30, -30),textcoords='offset points', fontsize=16,arrowprops=dict(arrowstyle='->', connectionstyle="arc3,rad=.2")) #其中參數(shù)xycoords='data' 是說基于數(shù)據(jù)的值來選位置, xytext=(+30, -30) 和 textcoords='offset points' 對于標(biāo)注位置的描述 和 xy 偏差值, arrowprops是對圖中箭頭類型的一些設(shè)置. plt.text(-3.7, 3, r'$This\ is\ the\ some\ text. \mu\ \sigma_i\ \alpha_t$',fontdict={'size': 16, 'color': 'r'})plt.show()
?
轉(zhuǎn)載于:https://www.cnblogs.com/kedaxiaohei/p/10172817.html
總結(jié)
以上是生活随笔為你收集整理的注解--python库--matplotlib的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。