检查matplotlib打印输出的函数
matplotcheck的Python项目详细描述
matplotcheck
用于测试不同类型matplotlib绘图的软件包,包括:
- 基本matplotlib绘图
- Geopandas空间矢量图
- 光栅图
- 时间序列图
- 叶状图
还有更多!
安装
要安装,请使用pip。--upgrade
是可选的,但它确保包覆盖
当您安装并拥有当前版本时。如果你没有包裹
但是您仍然可以使用--upgrade
参数。
pip install --upgrade matplotcheck
然后将其导入python。
import matplotcheck as mpc
背景
这个库是为了简化matplotlib图的自动打印过程而开发的。 可以通过多种方式创建视觉上相似的图,并保存不同的元数据。 我们的目标是通过创建一个简单的测试学生情节的方法来消除这些差异。
除此之外,我们还注意到特定绘图类型的断言的常见分组。
PlotBasicSuite
创建对象是为了避免在写出断言时重复,
并返回一个测试套件。要在创建套件后运行它,请使用unittest文本运行器。
示例
2D图,X轴标签包含“X”和Y轴标签,包含“Y”和“数据”
frommatplotcheck.casesimportPlotBasicSuiteimportpandasaspdimportunittestaxis=plt.gca()data=pd.DataFrame(data={“x”:xvals,“y”:yvals})suite=PlotBasicSuite(ax=axis,data_exp=data,xcol=”x”,ycol=”y”)xlabel_contains=[“x”],ylabel_contains=[“y”,”data”])results=unittest.TextTestRunner().run(suite)
空间光栅数据
的绘图示例包含空间光栅图像和空间多边形矢量数据的绘图
frommatplotcheck.casesimportPlotRasterSuiteaxis=plt.gca()suite=PlotRasterSuite(ax=axis,im_expected=image,polygons=polygons)results=unittest.TextTestRunner().run(suite)
如果您希望放弃分组到testsuites中,那么您可以直接使用断言。
2D图,X轴标签包含“X”和Y轴标签,包含“Y”和“数据”
frommatplotcheck.baseimportPlotTesterimportpandasaspdaxis=plt.gca()pt=PlotTester(axis)data=pd.DataFrame(data={“x”:xvals,“y”:yvals})pt.assert_xydata(data,“x”,“y”)pt.assert_xlabel_contains([“x”])pt.assert_ylabel_contains([“y”,“data”])
包含空间光栅图像和空间多边形矢量数据的绘图
frommatplotcheck.rasterimportRasterTesterfrommatplotcheck.vectorimportVectorTesteraxis=plt.gca()rt=RasterTester(axis)vt=VectorTester(axis)rt.assert_image(im_expected=image)vt.assert_polygons(polygons_expected=polygons)
注意:这个回购协议可能遗漏了创建matplotlib图的许多方法的边情况。 请随时提交错误!
活跃贡献者
- 莉亚·瓦瑟
开发设置(要移动到参与)
设置matplotcheck环境
conda env create -f environment.yml
conda activate matplotcheck-dev
然后设置所有的开发需求。
pip install -e .
pip install -r dev-requirements.txt
pre-commit install