1. 程式人生 > 實用技巧 >《SciencePlot:一行程式碼畫出美麗且專業的論文圖》

《SciencePlot:一行程式碼畫出美麗且專業的論文圖》

作為科研民工,在寫論文、作報告、做PPT時,對實驗結果進行圖形化展示是必不可少的工作。好的圖片給論文錦上添花,使讀者心曠神怡。

計算機專業向來不缺少專業的繪圖軟體,從Excel到PPT,從最近沸沸揚揚的Matlab到Matplotlib、pyplot、ggplot,乃至其他更為專業的軟體,著實豐富了我們的畫圖生活。

但是,這些軟體或工具的背後,常常需要我們付出更多的努力:調色、統一格式、展示要高大上,等等。

現在,一款開源的軟體工具包問世了:SciencePlots。它讓你用一行程式碼畫出天然高階且美觀的論文圖。

SciencePlots是一個依附於Matplotlib的擴充套件包,可以通過pip一鍵安裝:

pip install SciencePlots

然後我們在畫圖時,只需要一句with.plt.style.context(['science']):,就可以畫出非常美觀且專業的圖:

圖片來自github

是不是很美?

你還可以加一個選項with.plt.style.context(['science','ieee']):,就能畫出IEEE格式的圖:

圖片來自github

甚至是超美的散點圖:

圖片來自github

還能相容Jupyter Notebook:

圖片來自github

還有很多自定義的影象風格,保證節約我們的畫圖時間!

這個包預設會呼叫latex來畫圖,如果不想用latex(也不是完全需要),可以在context裡寫一個屬性'nolatex'即可。不然如果沒有安裝latex或latex路徑配置有問題,則會報錯。

好了,話不多說了,下載地址在這裡:

趕緊去體驗吧!

編輯於 07-04

Skip to content
PullrequestsIssues Marketplace Explore

/SciencePlots

master
1branch
1tag Go to fileAdd fileCode

Latest commit

garrettj403Bump version to 1.0.4 bdaa1d326 days ago

Git stats

Files

Type Name Latest commit message Commit time examples Add new style to add grid lines 4 months ago styles Add new style to add grid lines 4 months ago .gitignore gitignore: add dist directory 26 days ago CHANGES.md Add change log: CHANGES.md 26 days ago LICENSE Add license 2 years ago MANIFEST.in Format for PyPI 5 months ago README.md README: add more info on contributing to SciencePlots last month setup.py Bump version to 1.0.4 26 days ago

README.md

Science Plots

Matplotlib styles for scientific plotting

This repo has Matplotlib styles to format your plots for scientific papers, presentations and theses.

Installation

The easiest way to install SciencePlots is usingpip:

# for latest commit
pip install git+https://github.com/garrettj403/SciencePlots.git

# for lastest release
pip install SciencePlots

The pip installation will automatically move all of the*.mplstylefiles into the appropriate directory. If you like, you can also do this manually. First, clone the repository and then copy all of the*.mplstylefiles into your Matplotlib style directory. If you're not sure where this is, in an interactive python console type:

import matplotlib
print(matplotlib.get_configdir())

You should get back something like/home/garrett/.matplotlib. You would then put the*.mplstylefiles in/home/garrett/.matplotlib/stylelib/(you may need to create thestylelibdirectory).

Using the Styles

science.mplstyleis the main style from this repo. Whenever you want to use it, simply add the following to the top of your python script:

import matplotlib.pyplot as plt
 
plt.style.use('science')

You can also combine multiple styles together by:

plt.style.use(['science','ieee'])

In this case, theieeestyle will override some of the parameters from thesciencestyle in order to configure the plot for IEEE papers (column width, fontsizes, etc.).

To use any of the styles temporarily, you can use:

with plt.style.context(['science', 'ieee']):
    plt.figure()
    plt.plot(x, y)
    plt.show()

Examples

Thesciencestyle:

Thescience+gridstyles:

Thescience+ieeestyles for IEEE papers:

  • IEEE requires figures to be readable when printed in black and white. Theieeestyle also sets the figure width to fit within one column of an IEEE paper.

Thescience+scatterstyles for scatter plots:

Thescience+notebookstyles for Jupyter notebooks:

You can also combine these styles with the other styles that come with Matplotlib. For example, thedark_background+science+high-visstyles:

Note:See theexamples/directory for more!

Color Cycles

Thehigh-viscolor cycle:

Thebrightcolor cycle:

Thevibrantcolor cycle:

Themutedcolor cycle:

Theretrocolor cycle:

Note:Thebright,vibrantandmutedcolor cycles are fromPaul Tol's website.They are color-blind safe!

Help and Contributing

Please feel free to contribute to the SciencePlots repo! For example, it would be good to add new styles for different journals and add new color cycles. Before starting a new style or making any changes, please create an issue through theGitHub issue tracker. That way we can discuss if the changes are necessary and the best approach.

If you need any help with SciencePlots, please first check theFAQand search through theprevious GitHub issues. If you can't find an answer, create a new issue through theGitHub issue tracker.

You can checkoutMatplotlib's documentationfor more information on plotting settings.

FAQ

  1. Errors related to Latex:

    • If you get an error sayingRuntimeError: Failed to process string with tex because latex could not be found, this means that you do not have Latex installed on your computer (or at least that Python/Matplotlib can't find it). You have two options: (1) install Latex, or (2) disable Latex using theno-latexoption:

      plt.style.use(['science','no-latex'])
    • For Windows users, you may need to manually add Latex to your environment path (see issue).

SciencePlots in Academic Papers

The following papers useSciencePlots:

If you useSciencePlotsin your paper/thesis, feel free to add it to the list!

About

Matplotlib styles for scientific plotting

Topics

matplotlib-style-sheetsmatplotlib-figuresscientific-papersthesis-templatematplotlib-stylespython

Resources

Readme

License

MIT License

Releases1

v1.0.4Latest 26 days ago

Packages

No packages published

Used by4

Languages

Favorites Outline