deepin15.8 下 python3 matplotlib画图乱码问题解决

2018-08-14 03:49:00 by wst

python小技巧
git clone https://github.com/tracyone/program_font && cd program_font && ./install.sh

机器环境

  1. deepin 15.8
  2. anaconda3

解决方法

查看可用字体

转自:https://www.cnblogs.com/arkenstone/p/6411055.html

__author__ = 'Katherine'
from matplotlib.font_manager import FontManager
import subprocess

fm = FontManager()
mat_fonts = set(f.name for f in fm.ttflist)

output = subprocess.check_output(
    'fc-list :lang=zh -f "%{family}\n"', shell=True)
output = output.decode('utf-8')
# print '*' * 10, '系统可用的中文字体', '*' * 10
# print output
zh_fonts = set(f.split(',', 1)[0] for f in output.split('\n'))
available = mat_fonts & zh_fonts

print('*' * 10, '可用的字体', '*' * 10)
for f in available:
    print(f)

输出为(每个人可能不一样, 可有可能为空):

********** 可用的字体 **********
Droid Sans Fallback
HanaMinA

若没有可用字体,则执行以下步骤安装字体:

安装字体

  1. 首先需要安装中文字体

  2. git clone https://github.com/tracyone/program_font && cd program_font && ./install.sh

    git clone这一步有时非常慢,后来我直接下载完放到了百度云上(链接: https://pan.baidu.com/s/1kD_9mNDm4yVNSx_PIvkRKw 提取码: f978 复制这段内容后打开百度网盘手机App,操作更方便哦)

  3. 如果没有sudo权限,这一步会报错,修改install.sh文件为:

  4. #!/bin/bash
    # author:tracyone,tracyone@live.cn
    
    if [[ `uname` == 'Darwin' ]]; then
      # MacOS
      font_dir="$HOME/Library/Fonts/"
    else
      # Linux
      font_dir="${HOME}/.fonts/"
      mkdir -p $font_dir
    #  sudo mkdir -p /usr/share/fonts/MyFonts
    #  find . -regextype posix-egrep -iregex '.*\.tt[cf]$' -exec sudo cp {} /usr/share/fonts/MyFonts  \;
    fi
    
    echo "Install start..."
    find . -regextype posix-egrep -iregex '.*\.tt[cf]$' -exec cp {} ${font_dir}  \;
    #sudo fc-cache -f -v
    echo "Install finish..."

     

然后再次执行安装动作:

./install.sh 

清除缓存,这一步很关键,一定要执行

rm -rf ~/.cache/matplotlib/*

设置自己的字体,运行如下的测试程序

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from scipy import stats
# 虽然代码中没有用到此包,画3d图时依然要引入
from mpl_toolkits.mplot3d import Axes3D

mpl.rcParams['axes.unicode_minus'] = False
# 可通过前面代码查看可用字体,然后找个可用放这里
mpl.rcParams['font.sans-serif'] = 'HanaMinA'

if __name__ == "__main__":
    x1, x2 = np.mgrid[-5:5:51j, -5:5:51j]
    x = np.stack((x1, x2), axis=2)

    fig = plt.figure(figsize=(9, 8), facecolor='w')
    sigma = (np.identity(2), np.diag((3, 3)), np.diag((2, 5)), np.array(((2, 1), (2, 5))))
    for i in np.arange(4):
        ax = fig.add_subplot(2, 2, i + 1, projection='3d')
        norm = stats.multivariate_normal((0, 0), sigma[i])
        y = norm.pdf(x)
        ax.plot_surface(x1, x2, y, cmap=plt.cm.Accent, rstride=1, cstride=1, alpha=0.9, lw=0.5)
        ax.set_xlabel('X')
        ax.set_ylabel('Y')
        ax.set_zlabel('Z')
    plt.suptitle(u"二元高斯分布方差比较", fontsize=18)
    plt.tight_layout(1.5)
    plt.show()

 


Comments(133) Add Your Comment

Charlesnag
“I haven’t seen you in these parts,” the barkeep said, sidling during to where I sat. “Repute’s Bao.” He stated it exuberantly, as if solemn word of honour of his exploits were shared by settlers about multifarious a ‚lan in Aeternum. He waved to a unanimated butt hard by us, and I returned his token with a nod. He filled a field-glasses and slid it to me across the stained red wood of the excluding in the vanguard continuing. “As a betting man, I’d be delighted to wager a honourable piece of silver you’re in Ebonscale Reach on the side of more than the wet one's whistle and sights,” he said, eyes glancing from the sword sheathed on my hip to the bow slung across my back. https://image.google.bi/url?q=https://renewworld.ru/budet-li-russkiy-yazyk-v-new-world/
Yqrepj
buy lipitor 40mg pill <a href="https://lipiws.top/">buy atorvastatin 20mg online cheap</a> brand lipitor
Nxfpfi
baycip for sale - <a href="https://cipropro.top/keflexcapsule/">buy generic keflex</a> amoxiclav pill
Jkcvks
order ciprofloxacin online cheap - <a href="https://metroagyl.top/keflexcapsule/">keflex over the counter</a> buy augmentin 1000mg pill
Pwmxvl
metronidazole 200mg cheap - <a href="https://metroagyl.top/cefaclor/">cefaclor 250mg cheap</a> azithromycin pills
Zqance
order ciprofloxacin 500 mg for sale - <a href="https:/septrim.top/">ciprofloxacin 500mg brand</a> purchase erythromycin without prescription
Nczxrh
buy valacyclovir 500mg generic - <a href="https://gnantiviralp.com/starlix/">order nateglinide generic</a> zovirax 400mg brand
Qaojft
ivermectin india - <a href="https://keflexin.top/tetracycline/">sumycin online buy</a> order sumycin online cheap
Ysugcv
where to buy metronidazole without a prescription - <a href="https://metroagyl.top/">buy flagyl 200mg for sale</a> zithromax without prescription
Idlape
buy acillin medication <a href="https://ampiacil.top/doxycyclineantb/">buy monodox online cheap</a> purchase amoxicillin
Xxelbn
order furosemide generic - <a href="https://antipathogenc.com/prograf/">order prograf 5mg generic</a> purchase capoten pill
Osbpoh
order glycomet 500mg pills - <a href="https://gnantiacidity.com/duricef/">buy cefadroxil 250mg sale</a> lincomycin buy online
Mmurtu
how to buy retrovir - <a href="https://canadiangnp.com/rulide/">buy roxithromycin for sale</a> buy allopurinol 300mg sale
Acpzjj
clozaril generic - <a href="https://genonlinep.com/pepcid/">buy famotidine generic</a> buy pepcid tablets
Uhibyl
quetiapine 100mg pill - <a href="https://gnkantdepres.com/eskalith/">eskalith pills</a> eskalith without prescription
Fjzeoi
order clomipramine 25mg for sale - <a href="https://antdeponline.com/asendin/">asendin usa</a> doxepin 75mg pills
Xvenuw
atarax price - <a href="https://antdepls.com/buspar/">buy buspirone 5mg without prescription</a> buy amitriptyline no prescription
Tooadw
amoxiclav pills - <a href="https://atbioinfo.com/linezolid/">zyvox online order</a> order ciprofloxacin 1000mg generic
Qpdqmf
cheap amoxicillin tablets - <a href="https://atbioxotc.com/cefadroxil/">order cefadroxil sale</a> baycip cheap
Fzxysl
buy generic cleocin for sale - <a href="https://cadbiot.com/oxytetracycline/">order terramycin generic</a> buy chloromycetin generic
Fzbvvw
azithromycin 500mg oral - <a href="https://gncatbp.com/aciprofloxacin/">ciprofloxacin 500 mg cost</a> ciprofloxacin generic
Qgksut
ivermectina 6mg - <a href="https://antibpl.com/rferyc/">eryc uk</a> buy cefaclor paypal
Cutrto
order ventolin - <a href="https://antxallergic.com/oiphenergan/">phenergan uk</a> theophylline order
Qahmga
buy medrol without a prescription - <a href="https://ntallegpl.com/getazelastine/">purchase azelastine nasal spray</a> buy astelin 10 ml generic
Niowdy
order desloratadine 5mg - <a href="https://rxtallerg.com/flixotidespray/">buy cheap generic flixotide</a> albuterol pills
Nezeop
glyburide 5mg usa - <a href="https://prodeprpl.com/glipizide10/">buy glucotrol pills for sale</a> forxiga 10mg without prescription
Mcdmnz
generic glucophage 1000mg - <a href="https://arxdepress.com/sitagliptin50/">sitagliptin canada</a> precose 50mg us
Lniqpm
order repaglinide 1mg without prescription - <a href="https://depressinfo.com/jardiance25/">empagliflozin 25mg uk</a> buy jardiance pills for sale
Svcefw
terbinafine 250mg brand - <a href="https://treatfungusx.com/xgrifulvinvs/">buy griseofulvin generic</a> griseofulvin cheap
Kxqkbk
rybelsus drug - <a href="https://infodeppl.com/">cheap rybelsus 14mg</a> buy DDAVP sale
Crzixx
nizoral online order - <a href="https://antifungusrp.com/butenafinecream/">butenafine usa</a> buy itraconazole 100 mg generic
Tmauye
buy famciclovir 250mg online - <a href="https://amvinherpes.com/acyclovircream/">order acyclovir</a> purchase valcivir generic
Iqidpx
buy cheap lanoxin - <a href="https://blpressureok.com/dipyridamole100/">buy dipyridamole 100mg online</a> lasix 100mg ca
Zhnmci
buy microzide generic - <a href="https://norvapril.com/">purchase microzide for sale</a> order bisoprolol online cheap
Herrga
lopressor 50mg without prescription - <a href="https://bloodpresspl.com/hyzaar/">cozaar 50mg tablet</a> order nifedipine generic
Xdrrzy
nitroglycerin cost - <a href="https://nitroproxl.com/">generic nitroglycerin</a> diovan 160mg generic
Rgublg
rosuvastatin pile - <a href="https://antcholesterol.com/">crestor online worry</a> caduet online departure
Bjmngc
simvastatin tournament - <a href="https://canescholest.com/fenofibrate/">tricor lash</a> atorvastatin supply
Tvfomx
viagra professional nigger - <a href="https://edsildps.com/superavana/">avana motion</a> levitra oral jelly online storm
Dikuqb
dapoxetine temple - <a href="https://promedprili.com/cialiswithdapoxetine/">cialis with dapoxetine retreat</a> cialis with dapoxetine security
Yahwgw
cenforce fond - <a href="https://xcenforcem.com/cialistadalafil/">tadalafil pill</a> brand viagra online hell
Bqjwjp
brand cialis plant - <a href="https://probrandtad.com/forzestpills/">forzest belief</a> penisole warm
Dhphjn
cialis soft tabs condition - <a href="https://supervalip.com/viagrasuperactive/">viagra super active against</a> viagra oral jelly impressive
Qhpozb
brand cialis fred - <a href="https://probrandtad.com/apcalissx/">apcalis expect</a> penisole copy
Rbzdjw
cialis soft tabs pills screw - <a href="https://supervalip.com/cialisoraljelly/">cialis oral jelly arrangement</a> viagra oral jelly habit
Ioqymx
cenforce online lawn - <a href="https://xcenforcem.com/kamagrasildenafil/">kamagra online marsh</a> brand viagra pills farm
Wdxqtb
priligy host - <a href="https://promedprili.com/fildena/">fildena farm</a> cialis with dapoxetine experience
Neiqfb
acne treatment onto - <a href="https://placnemedx.com/">acne treatment dizzy</a> acne treatment appear
Quncui
asthma treatment sorrow - <a href="https://bsasthmaps.com/">asthma medication quill</a> asthma medication conceal
Mypsoi
uti treatment difference - <a href="https://amenahealthp.com/">treatment for uti even</a> uti antibiotics steel
Dnshws
prostatitis medications actual - <a href="https://xprosttreat.com/">prostatitis pills enter</a> prostatitis medications per
Gdpqio
valacyclovir debate - <a href="https://gnantiviralp.com/">valacyclovir online relax</a> valtrex online sullen
Vfdvwq
claritin pills depress - <a href="https://clatadine.top/">claritin pills greet</a> claritin pills greater
Icfhqd
dapoxetine beach - <a href="https://prilixgn.top/">priligy steel</a> dapoxetine frantic
Hiltau
claritin pills fond - <a href="https://clatadine.top/">loratadine medication remarkable</a> loratadine misery
Gezinp
ascorbic acid uniform - <a href="https://ascxacid.com/">ascorbic acid physician</a> ascorbic acid anywhere
Udxwjk
promethazine aloud - <a href="https://prohnrg.com/">promethazine blast</a> promethazine slight
Gordfm
clarithromycin section - <a href="https://gastropls.com/gncytotec/">cytotec pills defense</a> cytotec pills remain
Wxqagq
florinef pills sigh - <a href="https://gastroplusp.com/">fludrocortisone pills attention</a> lansoprazole decide
Riyvbw
buy rabeprazole pills - <a href="https://gastrointesl.com/domperidone/">motilium for sale</a> cost domperidone
Mepbxc
bisacodyl 5mg pill - <a href="https://gastroinfop.com/oxybutynin/">brand oxytrol</a> buy liv52 pills
Sjooqj
buy bactrim sale - <a href="https://ketiracet.com/">levetiracetam 500mg ca</a> order tobra sale
Pyatre
how to get eukroma without a prescription - <a href="https://dupsteron.com/">duphaston 10 mg sale</a> buy duphaston generic
Ronnfe
dapagliflozin us - <a href="https://precarbos.com/">how to buy acarbose</a> purchase precose pills
Oxmzyv
order fulvicin 250mg sale - <a href="https://gemfilopi.com/">lopid 300 mg uk</a> lopid 300mg usa
Wstjmi
dimenhydrinate 50mg drug - <a href="https://prasilx.com/">order generic prasugrel 10mg</a> risedronate 35mg usa
Cqpooa
purchase enalapril sale - <a href="https://xalanoprost.com/">cheap latanoprost</a> xalatan where to buy
Amdpey
order monograph 600 mg online - <a href="https://cilosetal.com/">order pletal 100mg sale</a> buy pletal 100 mg
Hjntri
feldene 20mg drug - <a href="https://rivastilons.com/">order exelon 6mg pills</a> exelon 6mg ca
Btyerz
purchase nootropil - <a href="https://nootquin.com/praziquantel/">praziquantel 600mg pills</a> buy sinemet 10mg generic
Atkenm
hydrea pills - <a href="https://hydroydrinfo.com/trecatorsc/">buy ethionamide</a> methocarbamol usa
Fyvcfk
depakote 250mg over the counter - <a href="https://adepamox.com/acetazolamide/">diamox 250 mg ca</a> topamax 100mg without prescription
Uulltj
norpace pills - <a href="https://anorpica.com/pregabal/">purchase lyrica online cheap</a> chlorpromazine 50 mg pill
Enxwmv
order cyclophosphamide online - <a href="https://cycloxalp.com/antivert/">meclizine 25mg price</a> cost vastarel
Fnjhjz
purchase aldactone generic - <a href="https://aldantinep.com/naltrexone/">naltrexone canada</a> buy naltrexone 50 mg pill
Dwvphq
how to get flexeril without a prescription - <a href="https://abflequine.com/olanzapine/">olanzapine 10mg brand</a> vasotec cost
Hieyom
buy zofran generic - <a href="https://azofarininfo.com/">buy ondansetron pills</a> cheap ropinirole 1mg
Bwryoi
ascorbic acid 500 mg us - <a href="https://mdacidinfo.com/isosorbidedinitrate/">generic isosorbide dinitrate</a> prochlorperazine buy online
Xtoevj
order durex gel online - <a href="https://xalaplinfo.com/">order durex gel online</a> cost latanoprost
Greios
rogaine online - <a href="https://hairlossmedinfo.com/">buy rogaine sale</a> proscar price
Pqwihy
buy generic arava for sale - <a href="https://infohealthybones.com/risedronate/">risedronate ca</a> buy cartidin paypal
Iudwpx
buy cheap generic verapamil - <a href="https://infoheartdisea.com/cardizem/">purchase diltiazem</a> cheap tenoretic
Wigwmi
tenormin for sale - <a href="https://heartmedinfox.com/carvedilol/">buy generic carvedilol over the counter</a> order carvedilol 25mg for sale
Blxxsa
buy atorvastatin generic - <a href="https://infoxheartmed.com/enalapril/">vasotec 10mg for sale</a> buy bystolic generic
Zngayv
gasex oral - <a href="https://herbalinfomez.com/diabecon/">diabecon brand</a> how to get diabecon without a prescription
Qcxjul
buy lasuna online cheap - <a href="https://infoherbalmz.com/diarex/">diarex cost</a> himcolin price
Wyooeh
buy speman generic - <a href="https://spmensht.com/finasteride/">cheap fincar</a> buy fincar no prescription
Dcbvyf
cheap finasteride online - <a href="https://finmenura.com/kamagra/">buy kamagra 200mg pills</a> uroxatral 10 mg generic
Cewcqe
order terazosin 5mg pill - <a href="https://hymenmax.com/tamsulosin/">buy generic tamsulosin online</a> cheap dapoxetine 30mg
Qrdwwx
how to buy oxcarbazepine - <a href="https://trileoxine.com/">cheap trileptal</a> synthroid 100mcg price
Rinbvu
cyclosporine cheap - <a href="https://asimusxate.com/methotrexate/">order methotrexate 2.5mg sale</a> buy generic colcrys for sale
Cuzcdw
duphalac oral - <a href="https://duphalinfo.com/betahistine/">betahistine sale</a> betahistine for sale online
Vnvcqn
deflazacort for sale - <a href="https://lazacort.com/">deflazacort pill</a> alphagan over the counter
Ndvtwj
buy besifloxacin for sale - <a href="https://besifxcist.com/">besivance tubes</a> purchase sildamax generic
Zxpqxc
buy neurontin 800mg generic - <a href="https://aneutrin.com/sulfasalazine/">sulfasalazine usa</a> buy generic sulfasalazine over the counter
Yywywf
benemid pills - <a href="https://bendoltol.com/carbamazepine/">tegretol 200mg usa</a> order generic tegretol
Ouqjrr
cheap colospa 135 mg - <a href="https://coloxia.com/etoricoxib/">buy arcoxia medication</a> pletal 100mg for sale
Qejlgj
celecoxib 100mg without prescription - <a href="https://celespas.com/indomethacin/">indocin order online</a> order indomethacin online
Vkgnhz
order diclofenac 50mg generic - <a href="https://dicloltarin.com/aspirin/">order aspirin online</a> buy aspirin generic
Qvklfl
how to buy rumalaya - <a href="https://rumaxtol.com/">order rumalaya online</a> order amitriptyline pill
Tgielp
pyridostigmine pills - <a href="https://mestonsx.com/asumatriptan/">imitrex 50mg without prescription</a> imuran pills
Ytedrr
order voveran pills - <a href="https://vovetosa.com/animodipine/">purchase nimotop generic</a> buy nimodipine generic
Kdhnzi
order lioresal sale - <a href="https://baclion.com/">generic baclofen 10mg</a> piroxicam 20 mg cost
Firmva
order mobic 7.5mg - <a href="https://meloxiptan.com/asrizatriptan/">maxalt canada</a> buy generic ketorolac
Kvqurx
buy cheap generic cyproheptadine - <a href="https://periheptadn.com/aszanaflex/">buy zanaflex generic</a> purchase tizanidine for sale
Dhpdzr
cheap trihexyphenidyl pills - <a href="https://voltapll.com.com/">buy artane tablets</a> voltaren gel buy online
Cbajuk
purchase cefdinir pill - <a href="https://omnixcin.com/clindamycin/">order cleocin gel</a> brand cleocin
Bnlxjl
purchase isotretinoin pills - <a href="https://aisotane.com/asavlosulfon/">avlosulfon usa</a> deltasone buy online
Ttsfjg
prednisone 10mg sale - <a href="https://apreplson.com/prednisolone/">omnacortil brand</a> buy generic zovirax
Jixgxr
buy acticin sale - <a href="https://actizacs.com/asbenzac/">generic benzac</a> purchase tretinoin
Aeucoa
buy betnovate paypal - <a href="https://betnoson.com/">betamethasone 20 gm for sale</a> purchase benoquin without prescription
Hfjwif
cheap augmentin 375mg - <a href="https://alevonted.com/">cheap levothroid online</a> synthroid over the counter
Mbofsk
cleocin 150mg brand - <a href="https://indometnp.com/">buy indocin 75mg generic</a> order indomethacin 75mg online cheap
Cnvqcj
order losartan 25mg without prescription - <a href="https://acephacrsa.com/">buy keflex 125mg pills</a> order cephalexin for sale
Yfpvtj
purchase crotamiton sale - <a href="https://aeuracream.com/abactroban/">bactroban ointment cost</a> buy aczone online cheap
Fttxmo
purchase modafinil online - <a href="https://sleepagil.com/melatonin/">order melatonin generic</a> melatonin drug
Xaquwi
zyban 150 mg uk - <a href="https://bupropsl.com/ayurslim/">ayurslim order online</a> buy shuddha guggulu without a prescription
Ehtpwc
progesterone brand - <a href="https://apromid.com/gynelotrimin/">how to buy ponstel</a> fertomid canada
Avurqe
xeloda 500 mg generic - <a href="https://xelocap.com/naproxen/">buy naprosyn sale</a> buy danocrine without prescription
Bosuda
norethindrone 5mg cheap - <a href="https://norethgep.com/yasmin/">yasmin order online</a> order yasmin for sale
Epggrm
order fosamax 70mg pills - <a href="https://pilaxmax.com/">where can i buy fosamax</a> buy medroxyprogesterone tablets
Eiiblx
buy dostinex 0.5mg for sale - <a href="https://adostilin.com/">dostinex 0.5mg without prescription</a> buy generic alesse for sale
Ibuyib
estrace 2mg usa - <a href="https://festrolp.com/ginette-35/">purchase ginette 35 without prescription</a> buy anastrozole medication
Jehpaj
正規品バイアグラ錠の正しい処方 - <a href="https://jpedpharm.com/">タダラフィル おすすめ</a> シアリスの飲み方と効果
Yscony
гѓ—гѓ¬гѓ‰гѓ‹гѓійЂљиІ©гЃ§иІ·гЃ€гЃѕгЃ™гЃ‹ - <a href="https://jpaonlinep.com/jazithromycin/">г‚ёг‚№гѓ­гѓћгѓѓг‚ЇгЃ®иіје…Ґ</a> г‚ёг‚№гѓ­гѓћгѓѓг‚Ї гЃЉгЃ™гЃ™г‚Ѓ
Jwmqbm
プレドニン通販 安全 - <a href="https://jpanfarap.com/jpadoxycycline/">ドキシサイクリン 値段</a> アキュテインジェネリック 通販
Hzhytn
eriacta centre - <a href="https://eriagra.com/">eriacta earth</a> forzest alter
Llljig
buy generic indinavir - <a href="https://confindin.com/fincar/">buy finasteride pills for sale</a> purchase voltaren gel cheap
Rvsvbt
valif pills anyway - <a href="https://avaltiva.com/tysecnidazolef/">secnidazole online</a> sinemet 10mg pills
Ofjsde
valif pills expedition - <a href="https://avaltiva.com/">valif pills devil</a> sinemet 10mg over the counter
Qoyafk
order provigil 200mg pill - <a href="https://provicef.com/lamivudine/">buy combivir</a> buy epivir tablets
Pcoxxj
ivermectin 3 mg for humans for sale - <a href="https://ivercand.com/carbamazepine/">cheap tegretol</a> brand tegretol 400mg
Rzuemd
promethazine 25mg canada - <a href="https://prometacin.com/jilincomycin/">buy lincocin no prescription</a> order generic lincomycin