Skip to content

ahacad-bots/py-cheat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Matplotlib

Labels

  • 旋转 label plt.xticks(rotation=45)

Colors

  • 手动正态颜色
norm = matplotlib.colors.Normalize(vmin=min(dataGoals.G), vmax=max(dataGoals.G))
colors = [matplotlib.cm.Blues(norm(value)) for value in dataGoals.G]

save fig

  • 防止文字导出时被砍掉一部分
plt.savefig('testfig.png',dpi=300, bbox_inches = "tight")

remove frames

mpl.rcParams['axes.spines.left'] = False
mpl.rcParams['axes.spines.right'] = False
mpl.rcParams['axes.spines.top'] = False
mpl.rcParams['axes.spines.bottom'] = False

Fonts

  • Seaborn 设置字体:
from matplotlib.font_manager import FontProperties
myfont = FontProperties(fname=r"yourfontpath", size=14)
sns.set(font=myfont.get_name())
  • Get all the fonts:
import matplotlib.font_manager
fpaths = matplotlib.font_manager.findSystemFonts()

for i in fpaths:
    f = matplotlib.font_manager.get_font(i)
    print(f.family_name)
  • 手动添加字体
fe = mpl.font_manager.FontEntry(
    fname='/usr/share/fonts/wenquanyi/wqy-zenhei/wqy-zenhei.ttc',
    name='wqy-zen')
mpl.font_manager.fontManager.ttflist.insert(0, fe) # or append is fine
mpl.rcParams['font.family'] = fe.name # = 'your custom ttf font name'
mpl.rcParams.update({"font.size": 10})

Pandas

show more columns and rows in Pandas DataFrame

pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)

Releases

No releases published

Packages

No packages published