如何更改 ipython 笔记本中的字体 [英] How to change font in ipython notebook

查看:23
本文介绍了如何更改 ipython 笔记本中的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 python 还很陌生,没有 html 经验.这个问题已经被问到,要么根本没有回答,要么没有足够详细地回答我在 iPython 中设置默认字体(不更改为浏览器).具体来说,css文件中必须放什么,应该使用哪个css文件?我使用的是 Windows 系统.

作为参考,这些是对下面链接的 SO 问题的回答:

  • #1: 中的未命名文件/usr/lib/python2.6/.../css/
  • 在 #1 的评论中:在浏览器中更改等宽字体- 工作,但字体是斜体
  • #2:custom.css 在配置文件子目录 /static/custom/custom.css

相关问题:

  1. 更改 ipython 笔记本字体类型
  2. 更改字体&ipython notebook 中的背景色
  3. 在 ipython notebook 中更改(恢复默认)字体(未回答)-

正如 #1 的答案评论中所建议的那样,在我的浏览器中更改等宽字体是有效的.但是字体是斜体的,这不是预期的.

解决方案

您可以将鼠标悬停在 .ipython 文件夹(即您可以在终端中输入 $ ipython locate/bash 或 CMD.exe Prompt 从你的 Anaconda Navigator 查看你的 ipython 所在的位置)

然后,在.ipython中,你会看到默认的profile_default目录.该目录将包含 static/custom/custom.css 文件.

您现在可以对这个 custom.css 文件应用更改.custom.css 文件中有很多样式供您使用或搜索.比如你可以看到这个链接(这是我自己定制的<代码>custom.css 文件)

基本上,这个 custom.css 文件会将更改应用于您的浏览器.您可以在 ipython 笔记本中使用检查元素来查看要更改的元素.然后,您可以更改 custom.css 文件.例如,您可以在 .CodeMirror pre 中添加这些块来更改字体以键入 Monaco

.CodeMirror pre {font-family: Monaco;字体大小:9pt;}

注意,现在对于 Jupyter notebook 版本 >= 4.1,自定义 css 文件移动到 ~/.jupyter/custom/custom.css.>

I am fairly new to python and have no html experience. The question has been asked and either not answered at all or not answered in enough detail for me to set the default font within iPython (not change to browser). Specifically, what has to be put in the css file and which css file should be used? I am on a Windows system.

For reference, these are in answer to the linked SO questions below:

  • in #1: an unnamed file in /usr/lib/python2.6/.../css/
  • in comment to #1: change monospace font in browser - worked but font is italic
  • in #2: custom.css in profile subdirectory /static/custom/custom.css

Related questions:

  1. Change ipython notebook font type
  2. Change font & background color in ipython notebook
  3. Changing (back to default) font in ipython notebook (unanswered) -

Edit: Changing the monospace font in my browser worked, as suggested in an answer comment of #1. However the font is italic, which is not what is intended.

解决方案

You can hover to .ipython folder (i.e. you can type $ ipython locate in your terminal/bash OR CMD.exe Prompt from your Anaconda Navigator to see where is your ipython is located)

Then, in .ipython, you will see profile_default directory which is the default one. This directory will have static/custom/custom.css file located.

You can now apply change to this custom.css file. There are a lot of styles in the custom.css file that you can use or search for. For example, you can see this link (which is my own customize custom.css file)

Basically, this custom.css file apply changes to your browser. You can use inspect elements in your ipython notebook to see which elements you want to change. Then, you can changes to the custom.css file. For example, you can add these chunk to change font in .CodeMirror pre to type Monaco

.CodeMirror pre {font-family: Monaco; font-size: 9pt;}

Note that now for Jupyter notebook version >= 4.1, the custom css file is moved to ~/.jupyter/custom/custom.css instead.

这篇关于如何更改 ipython 笔记本中的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆