bonst ·¢±íÓÚ 2021-3-13 14:31:10

matplotlibÖÐÎÄÏÔʾÎÊÌâ

Õâ¸öÊÇÎҵĴúÂë# encoding: utf-8
import 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)

bonst ·¢±íÓÚ 2021-3-13 15:54:39

˳±ã˵һÏÂÎÒµÄmatplotlib°æ±¾ÊÇ3.3.4

˽¤Ï¤ê ·¢±íÓÚ 2021-3-13 20:13:40

ÎÒÓÃÄãµÄ´úÂë¿ÉÒÔÔËÐÐ
ÎÒÓõÄanacoda
ÎÒ·¢²»À´Í¼Æ¬

˽¤Ï¤ê ·¢±íÓÚ 2021-3-13 20:14:31

ÏÔʾµÄÊÇÖÐÎÄ

bonst ·¢±íÓÚ 2021-3-13 23:43:04

˽¤Ï¤ê ·¢±íÓÚ 2021-3-13 20:14
ÏÔʾµÄÊÇÖÐÎÄ

ÄѵÀÊÇÎұ༭Æ÷µÄÎÊÌâÂ𣬵«ÊÇÎÒÓÃIDELÔËÐÐÒ²ÊÇÕâÑù£¬ÎÒÓõÄÊÇvscode

bonst ·¢±íÓÚ 2021-3-13 23:43:41

˽¤Ï¤ê ·¢±íÓÚ 2021-3-13 20:13
ÎÒÓÃÄãµÄ´úÂë¿ÉÒÔÔËÐÐ
ÎÒÓõÄanacoda
ÎÒ·¢²»À´Í¼Æ¬

ÓÃÁËIDLEÔËÐÐÒ²²»ÐÐ

˽¤Ï¤ê ·¢±íÓÚ 2021-3-14 11:16:22

bonst ·¢±íÓÚ 2021-3-13 23:43
ÓÃÁËIDLEÔËÐÐÒ²²»ÐÐ

²»ÖªµÀ

putuo3 ·¢±íÓÚ 2021-4-5 23:52:52

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]
²é¿´ÍêÕû°æ±¾: matplotlibÖÐÎÄÏÔʾÎÊÌâ