2023年9月4日

Python: Matplotlib的文本支持 / 数学表达式 matplotlib.axes.Axes.text

Text https://matplotlib.org/stable/tutorials/text/index.html#text matplotlib has extensive text support, including support for mathematical expressions, truetype support for raster and vector outputs, newline separated text with arbitrary rotations, and Unicode support. These tutorials cover the basics of working with text in Matplotlib. matplotlib.axes.Axes.text https://matplotlib.org/stable/api/…
2023年9月4日

Python: Matplotlib Axes.plot 参数 fmt 格式字符串标记颜色/标记/线条

matplotlib.axes.Axes.plot https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot.html#matplotlib-axes-axes-plot Axes.plot(*args, scalex=True, scaley=True, data=None, **kwargs)[source] Plot y versus x as lines and/or markers. Call signatures: plot([x], y, [fmt], *, data=None, **kwargs) plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs) The coordinates of the points or line nodes are…
2023年9月4日

Python: 函数签名 Function Signature

什么是函数签名 函数签名(或者类型签名或方法签名)定义了函数或方法的输入与输出 签名可包含:  参数及参数的类型    返回值及其类型    可能抛出或传出的异常    该方法在面向对象程序中可用性方面的信息(如public、static或prototype) JavaScript中的签名 JavaScript是一钟松散型或动态语言。这意味着你不必提前声明变量的类型。类型将在程序处理时自动确定。JavaScript中的签名仍然可以为你提供有关该方法的一些信息: MyObject.prototype.myFunction(value) 该方法是安装在一个名为MyObject的对象上面。 该方法安装在MyObject的原型上(因此它是一个实例方法),而不是static、或pulic 该方法名为myFunction. 该方法接受一个…
2023年9月4日

Python: Matplotlib 两种使用Matplotlib绘图的方法 / 编码风格

Coding styles https://matplotlib.org/stable/tutorials/introductory/quick_start.html#coding-styles The explicit and the implicit interfaces As noted above, there are essentially two ways to use Matplotlib: Explicitly create Figures and Axes, and call methods on them (the "object-oriented (OO) style", 即面向对象的编码风格). Rely on pyplot to implicitly create and manage the Figures and Axes, and use pyplot functions for…
2023年9月3日

Python: Matplotlib matplotlib.pyplot.figure layout {'constrained', 'compressed', 'tight', 'none', LayoutEngine, None}

matplotlib.pyplot.figure https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html#matplotlib-pyplot-figure matplotlib.pyplot.figure(num=None, figsize=None, dpi=None, *, facecolor=None, edgecolor=None, frameon=True, FigureClass=<class 'matplotlib.figure.Figure'>, clear=False, **kwargs)[source] Create a new figure, or activate an existing figure. Parameters: ...…
2023年9月3日

Python: Pandas DataFrame.rename 重命名列或索引标签 / 修改索引中指定的某一个值

pandas.DataFrame.rename https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.rename.html#pandas-dataframe-rename DataFrame.rename(mapper=None, *, index=None, columns=None, axis=None, copy=None, inplace=False, level=None, errors='ignore')[source] Rename columns or index labels. Function / dict values must be unique (1-to-1). Labels not contained in a dict / Series will be left as-is. E…
2023年9月2日

Python: Pandas DataFrame.fillna fill method : {'backfill', 'bfill', 'pad', 'ffill', None}

1. 简介 专门用来处理 NA 或 NaN 值。 2. 语法参数 语法:DataFrame.fillna(value=None, method=None, axis=None, inplace=False, limit=None, downcast=None) 参数: value: 可以是常数、字典、数组、数据框。该选项决定了将NA或者NaN填充的内容。 method: 可以是{‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, None},默认是None。 pad/ffill:用前一个非缺失值去填充该缺失值; backfill/bfill:用下一个非缺失值填充该缺失值; None:指定一个值(value)去填充缺失值。 axis: 可以是{0 or ‘index’, 1 or ‘columns’},决定填充的方向轴,按行填充还是按列填充。 inplace…
2023年9月2日

Python: Pandas AttributeError: 'DataFrame' object has no attribute 'ix'

1. 问题概述: 运行以下代码: In [39]: df Out[39]: A B C first second bar one 0.895717 0.410835 -1.413681 two 0.805244 0.813850 1.607920 baz one -1.206412 0.132003 1.024180 two 2.565646 -0.827317 0.569605 foo one 1.431256 -0.076467 0.875906 two 1.340309 -1.187678 -2.211372 qux one -1.170299 1.130127 0.974466 two -0.226169 -1.436737 -2.006747 In [45]: df.ix[[('bar', 'two'), ('qux', 'one')]] 会抛出以下错误: Out[45]: ------------------…
2023年9月2日

Python: SyntaxError: f-string: expecting '}'

这段代码: tasks = ['markup', 'media', 'script'] print(f'Initializing project with the following tasks:{ ' '.join(tasks) }') 报错: File "project.py", line 85 print(f'Initializing project with the following tasks:{ ' '.join(tasks) }') SyntaxError: f-string: expecting '}' 2. 相关原因: 因为f-string使用了两次单引号。 3. 解决办法: 单引号里面使用双引号。 f'Initializing project with the following tasks:{ " ".join(tasks) }'…
2023年9月1日

Python: Numpy 数组按 元组 列表 数组 索引的异同

Indexing on ndarrays(N-dimensional array) https://numpy.org/doc/stable/user/basics.indexing.html#indexing-on-ndarrays See also Indexing routines ndarrays can be indexed using the standard Python x[obj] syntax, where x is the array and obj the selection. There are different kinds of indexing available depending on obj: basic indexing, advanced indexing and field access. Most of the following examples show the…