一个简单的默认绘图工具
saneplot的Python项目详细描述
一些基本的二维matplotlib绘图的简单包装,它有一些正常的默认值。主要用于个人用途。
动机和用例:
- Quickly set up multiple plot parameters (font sizes, text position, curve colors, x and y scales) without having to remember how to do that; provide some sane defaults
- Have all this code in one place and not scattered around multiple jupyter notebooks
- All of the above allows to quickly create plots of 2d dimensional data
用法
所有的事情都是由saneplot类完成的。控制绘图的初始化参数为:
- ^{tt1}$ - the size of the plot
- ^{tt2}$ - the legend location
- ^{tt3}$ - color of the legend background
- ^{tt4}$ - these two parameters control the font. I only set them to use Cyrillic characters
- ^{tt5}$ - legend font size
- ^{tt6}$ - tick label size
- ^{tt7}$ - set the size of the X and Y axis labels
- ^{tt8}$ - set the text size
- ^{tt9}$ - the width of the curves being plotted
- ^{tt10}$ - the size of the markers being plotted
- ^{tt11}$ - either None or a tuple/list; if set, sets the X-limits of the plot
- ^{tt12}$ - either None or a tuple/list; if set, sets the Y-limits of the plot
- ^{tt13}$ - either None or a string; if set, will place text somewhere on the plot
- ^{tt14}$ - controls the relative X-position of the text (thus, a value of 0.5 will place the text in the middle of the plot with respect to the X-axis)
- ^{tt15}$ - controls the absolute X-position of the text. If text_x_rel is set, will not do anything
- ^{tt16}$ - controls the relative Y-position of the text (thus, a value of 0.5 will place the text in the middle of the plot with respect to the Y-axis)
- ^{tt17}$ - controls the absolute Y-position of the text. If text_x_rel is set, will not do anything
- ^{tt18}$ - if set to 0, the X axis is normal (linear). If different from 0, then the X axis is a log-axis with base equal to ^{tt19}$
- ^{tt20}$ - if set to 0, the Y axis is normal (linear). If different from 0, then the X axis is a log-axis with base equal to ^{tt21}$
- ^{tt22}$ - the label for the X axis
- ^{tt23}$ - the label for the Y axis
- ^{tt24}$ - sets the line styles. Can be either ^{tt25}$, ^{tt26}$ or a list. If it is a list, curve number N on the plot will be plotted with a style set by the element number (N-1) % len(linechange) of the list. The list corresponding to ^{tt27}$: [‘k-‘, ‘k–’, ‘ko’, ‘k^’, ‘k:’, ‘k*’] The list corresponding to ^{tt28}$: [‘k’, ‘g’, ‘b’, ‘r’, ‘c’]
方法是:
- ^{tt29}$ - adds text specified during the initialization. You can override the originally set textsize. Returns the Figure object.
- ^{tt30}$ - plots the curve specified by the (x,y) arrays. The label is set by the ^{tt31}$ parameter, and the originally set linewidth and markersize can be overridden. Returns the Figure object.
- ^{tt32}$ - show the legend. Returns the Figure object.
- ^{tt33}$ - returns the Figure object.
示例
这可以插入到添加了%matplotlib inline的jupyter笔记本中,并将在那里显示结果图。
import numpy as np from saneplot import SanePlot x = np.linspace(0, 30, 100) y1 = np.sin(x) * 1000 + 4000 y2 = np.cos(x) * 1000 + 4000 y3 = x**2 * 1000 sp = SanePlot(x_label='x', y_label='y', text='(a)', text_x_abs=10, text_y_rel=0.5) sp.plot(x, y1, '0') sp.plot(x, y2+100, 'y2', linewidth=4) sp.plot(x, y2+500, 'y2', linewidth=4) sp.plot(x, y2+1000, 'y2', linewidth=3) sp.plot(x, y2+2000, 'y2', linewidth=3) sp.plot(x, y2+4000, 'y2', linewidth=4) sp.plot(x, y2+8000, 'y2', linewidth=5) sp.add_text(textsize=10) sp.legend()
版本历史记录
- 0.1 (01 February 2017) - first working version of the package created