一个简单的默认绘图工具

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在netbeans GUI中使用checknode创建JTree?   java事件无限循环SWT   java Thymeleaf空值检查   javajavax。同样是加密JDK源代码   java getColumnIndex访问外部内存中的特定文件夹   无法在Java代码中打开特定的JAR文件   java如何使用安全约束来保护url的一部分?   windows如何从命令行安装/删除Java快速启动服务   JavaSpring数据JPA保存新实体并获取其所有依赖项   swing Java JButton大小问题   IF语句可以在数学中使用吗。麦克斯在爪哇?   java如何使用POI设置空白excel单元格   java在签名为return int的方法中返回null?   java思想,如何将多个mircoservice项目放在同一个窗口中   直接从intelliJ在系统终端上运行java程序?   java通过POST从React应用程序向Spring Boot发送数组