两侧同时换到之前的修订记录前一修订版后一修订版 | 前一修订版 |
atk:plt脚本与应用实践 [2018/04/11 20:13] – [定义字体] fermi | atk:plt脚本与应用实践 [2018/04/14 10:09] (当前版本) – [数据线] fermi |
---|
====== plt脚本与应用实践 ====== | ====== plt 作图脚本与应用实践 ====== |
| |
QuantumATK 使用 matplotlib 作图,绝大多数时候,作图可以在Virtual NanoLab上通过鼠标操作作图定制。从2017版开始,用户可以将二维数据作图保存成plt脚本(实际为python语言脚本),这样做有很多好处: | **关键词:atkpython,能带,DOS,matplotlib** |
| |
| 使用 QuantumATK 作图时可以在Virtual NanoLab上通过鼠标操作对作图进行定制并导出需要的图片格式。从2017版开始,用户可以将二维数据作图保存成plt脚本(实际为python语言脚本),这样做有很多好处: |
* 可以保存用户自己设置的自定义图像,下次直接打开,不用再重新设置;也便于与同事共享相关的数据; | * 可以保存用户自己设置的自定义图像,下次直接打开,不用再重新设置;也便于与同事共享相关的数据; |
* 可以对数据进行导出、修改等操作; | * 可以对数据进行导出、修改等操作; |
'color' : 'red', | 'color' : 'red', |
'weight' : 'normal', | 'weight' : 'normal', |
| 'variant': 'normal', |
'size' : 20, | 'size' : 20, |
} | } |
可选项: | 可选项: |
| |
* family: A list of font names in decreasing order of priority. The items may include a generic font family name, either ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, or ‘monospace’. In that case, the actual font to be used will be looked up from the associated rcParam in matplotlibrc. | * family: 可使用的名称有 ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, or ‘monospace’ (这些字体的实际效果依赖于系统环境);还可以直接使用操作系统的字体名称,例如:‘Arial’,‘Courier New’,‘Times New Roman’等等。 |
* style: Either ‘normal’, ‘italic’ or ‘oblique’. | * style: 可选 ‘normal’, ‘italic’ or ‘oblique’; |
* variant: Either ‘normal’ or ‘small-caps’. | * variant: 可选 ‘normal’ or ‘small-caps’; |
* stretch: A numeric value in the range 0-1000 or one of ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’ or ‘ultra-expanded’ | * stretch: 可选 0-1000 数值或以下字符串 ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’ or ‘ultra-expanded’; |
* weight: A numeric value in the range 0-1000 or one of ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’ | * weight: 可选 0-1000 的数值或者以下字符串 ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’; |
* size: Either an relative value of ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’ or an absolute font size, e.g., 12 | * size: 可选绝对字体大小(例如 20)或以下字符串 ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’。 |
| |
| |
<code python> | <code python> |
axes_0.set_title(u'Bandstructure of Silicon', fontdict=fontdd, loc='right') | axes_0.set_title(u'Bandstructure of Silicon', fontdict=fontdd, loc='right') |
| </code> |
| |
| ==== 绘图尺寸、精度 ==== |
| |
| 找到开头的pyplot一句,可控制绘图尺寸、精度和颜色。这个选项仅影响图形显示,最后导出时,依赖于实际的缩放。 |
| |
| <code> |
| figure = pyplot.figure(figsize=(4,3), dpi=150, facecolor="yellow") |
</code> | </code> |
| |
</code> | </code> |
| |
线型: | === 线型(line style)定义 === |
| '-' or 'solid' | solid line | | | '-' or 'solid' | solid line | |
| '--' or 'dashed' | dashed line | | | '--'(双短线) or 'dashed' | dashed line | |
| '-.' or 'dashdot' | dash-dotted line | | | '-.' or 'dashdot' | dash-dotted line | |
| ':' or 'dotted' | dotted line | | | ':' or 'dotted' | dotted line | |
| '' | draw nothing | | | '' | draw nothing | |
| |
定义marker形状,请参考:https://matplotlib.org/api/markers_api.html | === marker形状定义 === |
| |
| marker description |
| | "." | point | |
| | "," | pixel | |
| | "o" | circle | |
| | "v" | triangle_down | |
| | "$^$" | triangle_up | |
| | "<" | triangle_left | |
| | ">" | triangle_right | |
| | "1" | tri_down | |
| | "2" | tri_up | |
| | "3" | tri_left | |
| | "4" | tri_right | |
| | "8" | octagon | |
| | "s" | square | |
| | "p" | pentagon | |
| | "P" | plus (filled) | |
| | "*" | star | |
| | "h" | hexagon1 | |
| | "H" | hexagon2 | |
| | "+" | plus | |
| | "x" | x | |
| | "X" | x (filled) | |
| | "D" | diamond | |
| | "d" | thin_diamond | |
| | "$|$" | vline | |
| | "_" | hline | |
| | TICKLEFT | tickleft | |
| | TICKRIGHT | tickright | |
| | TICKUP | tickup | |
| | TICKDOWN | tickdown | |
| | CARETLEFT | caretleft (centered at tip) | |
| | CARETRIGHT | caretright (centered at tip) | |
| | CARETUP | caretup (centered at tip) | |
| | CARETDOWN | caretdown (centered at tip) | |
| | CARETLEFTBASE | caretleft (centered at base) | |
| | CARETRIGHTBASE | caretright (centered at base) | |
| | CARETUPBASE | caretup (centered at base) | |
| | "None", " " or "" | nothing | |
| |
| 更多定义请参考:[[https://matplotlib.org/api/markers_api.html]] |
| |
| |
</code> | </code> |
| |
经过如上设置,能带作图示例如下: | ==== 进一步加工和导出 ==== |
| |
| 经过如上设置,plt脚本可能无法在VNL的2D plot editor里作图,但仍然可以用上述第二种方法在cmd命令行作图。示例如下: |
| |
| {{ :atk:plt-final-result.png?500 |}} |
| |
| 此时,仍然可以进一步使用作图工具调整一些性质(点击绿色“对号”),以便导出。 |
| |
| 点击“磁盘”图标,导出png(像素受限)或pdf(任意缩放)。 |
{{ :atk:plt_band_modified.png?400 |}} | {{ :atk:plt_band_modified.png?400 |}} |
| |
| |