我使用以下方法创建了一个图形:
import matplotlib.pyplot as plt
%matplotlib inline
fig1 = plt.figure(figsize=(2, 2), dpi=100)
Run Code Online (Sandbox Code Playgroud)
我想提高图形的分辨率,所以我将dpifig1从100增加到200。但是,这将像素尺寸从(200, 200)更改为(400, 400),这是我不想要的。如果我让 dpi=200 和 figsize=(1, 1),像素尺寸仍然是 (200, 200),但图像看起来很有趣。请在此处查看我的 Jupyter 笔记本的输出。
Matplotlib 中有没有办法在 Jupyter 中渲染时增加fig1的分辨率而不改变其像素尺寸?
(注意:我用来生成上面链接的数字的代码来自这个问题。)
我想遍历向量中所有相邻对元素。例如,如果我有一个vector {1, 2, 3, 4},我希望我的迭代器返回以下内容:
(1, 2)
(2, 3)
(3, 4)
Run Code Online (Sandbox Code Playgroud)
我知道如何使用以下方法一次遍历一个元素:
(1, 2)
(2, 3)
(3, 4)
Run Code Online (Sandbox Code Playgroud)
但是我也不知道如何获得下一个要素。
我同时迭代多个列表,并希望我的生成器生成元素及其索引。如果我有两个列表,我会使用嵌套的 for 循环:
for i_idx, i_val in enumerate(list_0):
for j_idx, j_val in enumerate(list_1):
print(i_idx, i_val, j_idx, j_val)
Run Code Online (Sandbox Code Playgroud)
但是,由于我有两个以上的列表,嵌套的解决方案很快变得难以辨认。我通常会使用 itertools.product 整齐地获得我的列表的笛卡尔乘积,但这种策略不允许我获得每个列表中元素的单独索引。
这是我迄今为止尝试过的:
>>> from itertools import product
>>> list_0 = [1,2]
>>> list_1 = [3,4]
>>> list_2 = [5,6]
>>> for idx, pair in enumerate(product(list_0, list_1, list_2)):
... print(idx, pair)
0 (1, 3, 5)
1 (1, 3, 6)
2 (1, 4, 5)
3 (1, 4, 6)
4 (2, 3, 5)
5 (2, 3, 6)
6 (2, 4, 5)
7 (2, 4, …Run Code Online (Sandbox Code Playgroud) 我使用Seaborn 文档中的这个示例来生成下图。
import seaborn as sns
tips = sns.load_dataset("tips")
g = sns.relplot(x="total_bill", y="tip", hue="day", col="time", data=tips)
Run Code Online (Sandbox Code Playgroud)
如何强制 x 轴或 y 轴使用不同的比例(例如,右侧子图中的 x 范围为 (0, 100))?
我尝试传递sharex=False给 replot 函数,但这不是有效的关键字。