matplotlibÖÐÎÄÏÔʾÎÊÌâ
Õâ¸öÊÇÎҵĴúÂë# encoding: utf-8import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif']=['SimHei'] # ÓÃÀ´Õý³£ÏÔʾÖÐÎıêÇ©
plt.rcParams['axes.unicode_minus']=False # ÓÃÀ´Õý³£ÏÔʾ¸ººÅ
x = np.arange(0,0.5,0.01)
x1 = x*np.pi
fig = plt.figure(1,figsize=(8,6))
plt.plot(x1, np.cos(x*np.pi), label = 'cos(x)', color = 'blue')
plt.plot(x1, np.tan(x*np.pi), label = 'tan(x)', color = 'green')
# ÇúÏß½»µã×ø±ê
a = np.arcsin((np.sqrt(5)-1)/2)
b = np.cos(a)
# c´ú±íÑÕÉ«£¬edgecolor´ú±íµãÂÖÀªÑÕÉ«£¬s´ú±íµãµÄ´óС
plt.scatter(a, b, c= 'r', edgecolor = 'none', s=45) # (2k¦Ð+arcsin(¡Ì5-1)/2,(3-¡Ì5)/2)
plt.tick_params(axis = 'both',labelsize = 10) # ÉèÖúá×Ý×ø±ê¿Ì¶È´óС
# ʵÏÖÐéÏß²¿·Ö
c = np.arange(0, b, 0.05)
d = []
for index in c:
if index != len(c):
d.append(a)
else:
break
e = np.arange(0, a, 0.05)
f = []
for index in e:
if index != len(e):
f.append(b)
else:
break
plt.plot(d, c, color = 'black',linestyle = '--')
plt.plot(e, f, color = 'black',linestyle = '--')
# ÇúÏß½»µã´¦¼ýÍ·±ê×¢
plt.annotate('½»µã',xy=(a,b),xytext=(a+0.2,b+0.2),
arrowprops=dict(facecolor='black',shrink=0.1,width=1))
plt.axis() # ÉèÖÃ×ø±êÖáµÄ·¶Î§Îªx=,y=
plt.grid(True) # ÏÔʾÍø¸ñ
plt.legend()# ÏÔʾ±êÇ©
plt.title('º¯Êý¶Ô±È',fontdict={'fontsize':25,'weight' : 'bold','horizontalalignment': 'center'}) #ÉèÖò¢ÏÔʾͼÏñÃû³Æ
plt.show()
Õâ¸öÊÇÎҵĴíÎó,ÎÒ²»Ã÷°×ÎÒÒѾÉèÖÃÁËÖÐÎÄÏÔʾµÄ´úÂë,ÒÔÇ°Ò²ÄÜÕý³£ÏÔʾµÄ,µ«ÊÇ×î½ü¾Í²»ÄÜÔËÐÐÁË,³öÏÖÁËÒ»ÏÂÐÅÏ¢.
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128) ˳±ã˵һÏÂÎÒµÄmatplotlib°æ±¾ÊÇ3.3.4 ÎÒÓÃÄãµÄ´úÂë¿ÉÒÔÔËÐÐ
ÎÒÓõÄanacoda
ÎÒ·¢²»À´Í¼Æ¬ ÏÔʾµÄÊÇÖÐÎÄ Ë½¤Ï¤ê ·¢±íÓÚ 2021-3-13 20:14
ÏÔʾµÄÊÇÖÐÎÄ
ÄѵÀÊÇÎÒ±à¼Æ÷µÄÎÊÌâÂ𣬵«ÊÇÎÒÓÃIDELÔËÐÐÒ²ÊÇÕâÑù£¬ÎÒÓõÄÊÇvscode ˽¤Ï¤ê ·¢±íÓÚ 2021-3-13 20:13
ÎÒÓÃÄãµÄ´úÂë¿ÉÒÔÔËÐÐ
ÎÒÓõÄanacoda
ÎÒ·¢²»À´Í¼Æ¬
ÓÃÁËIDLEÔËÐÐÒ²²»ÐÐ bonst ·¢±íÓÚ 2021-3-13 23:43
ÓÃÁËIDLEÔËÐÐÒ²²»ÐÐ
²»ÖªµÀ import matplotlib.font_manager as fm
myfont = fm.FontProperties(fname=r'D:\test\FZHTK.ttf') #ÎÒϲ»¶·½ÕýºÚÌ壬Ҳ¿ÉÒÔÓÃsimhei.ttf¼´ºÚÌå
ax.set_title("ƽ·½Êý",fontproperties=myfont,fontsize=32)
Ò³:
[1]