找到 1033 篇文章 关于 Matplotlib

如何交互式更新 matplotlib 的 imshow() 窗口?

Rishikesh Kumar Rishi
更新于 2021年4月10日 07:50:08

4K+ 阅读量

为了绘制交互式的 matplotlib 的 imshow 窗口,我们可以采取以下步骤 -使用 subplots() 方法,创建图形和一组子图。使用 numpy 创建一个数组来绘制图像。使用 imshow() 方法显示图像。要创建滑块轴,请创建一个轴和一个滑块,facecolor=yellow。为了在更改滑块时更新图像,我们可以编写一个用户定义的方法,即 update()。使用 draw_idle() 方法,在控制权返回到 GUI 事件循环后请求小部件重绘。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt from matplotlib.widgets import Slider ... 阅读更多

绘制曲线以区分 Matplotlib 中的反锯齿

Rishikesh Kumar Rishi
更新于 2021年4月10日 07:47:44

206 阅读量

为了通过曲线区分反锯齿,我们可以采取以下步骤 -使用 subplot() 方法向当前图形添加子图,其中 nrows=1,ncols=2 和 index=1。使用 plot() 方法绘制曲线,其中 antialiased 标志为 false,颜色为红色。使用 legend() 方法将图例放置在左上角。使用 subplot() 方法向当前图形添加子图,其中 nrows=1,ncols=2 和 index=2。使用 plot() 方法绘制曲线,其中 antialiased 标志为 true,颜色为绿色。使用 legend() 方法将图例放置在右上角。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt ... 阅读更多

在 Matplotlib 中将图例作为单独的图片获取

Rishikesh Kumar Rishi
更新于 2021年4月10日 07:43:34

3K+ 阅读量

为了将图例作为单独的图片获取,我们可以采取以下步骤 -使用 numpy 创建 x 和 y 点。使用 figure() 方法创建一个新图形,或激活一个现有的图形,用于线图和图例图图形。使用 add_subplot() 方法在 nrow=1,ncols=1 和 index=1 处,将“~.axes.Axes”添加为子图排列的一部分。使用 x、y 和 y1 点创建 line1 和 line2。放置 line1 和 line2 的图例,设置有序标签,放在中心位置。使用 savefig() 方法仅保存带图例的图形。示例import numpy as np from matplotlib import pyplot as plt x = np.linspace(1, 100, ... 阅读更多

Python 中的对数 Y 轴 bin

Rishikesh Kumar Rishi
更新于 2021年4月10日 07:38:49

3K+ 阅读量

为了在 Python 中绘制对数 Y 轴 bin,我们可以采取以下步骤 -使用 numpy 创建 x 和 y 点。使用 yscale() 方法设置 Y 轴刻度。使用 plot() 方法绘制 x 和 y 点,linestyle="dashdot" 和 label="y=log(x)"。要激活线的标签,请使用 legend() 方法。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 100, 1000) y = np.log(x) plt.yscale('log') plt.plot(x, y, c="red", lw=3, linestyle="dashdot", label="y=log(x)") plt.legend() plt.show()输出阅读更多

如何在 Matplotlib 中隐藏轴和网格线?

Rishikesh Kumar Rishi
更新于 2023年9月12日 01:31:20

41K+ 阅读量

为了隐藏轴(X 和 Y)和网格线,我们可以采取以下步骤 -使用 numpy 创建 x 和 y 点。使用 plot() 方法绘制一条水平线(y=0)作为 X 轴,并使用 linestyle、labels。使用 plot() 方法绘制 x 和 y 点,并使用 linestyle、labels。要隐藏网格,请使用 plt.grid(False)。要隐藏轴,请使用 plt.axis('off')要激活标签的图例,请使用 legend() 方法。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-10, 10, 50) y = np.sin(x) plt.axhline(y=0, c="green", linestyle="dashdot", label="y=0") plt.plot(x, y, c="red", lw=5, linestyle="dashdot", label="y=sin(x)") plt.grid(False) plt.axis('off') ... 阅读更多

如何绘制 matplotlib 等值线?

Rishikesh Kumar Rishi
更新于 2021年4月10日 07:33:48

300 阅读量

为了绘制 matplotlib 等值线,我们可以采取以下步骤 -使用 numpy 创建 x、y 和 h 的数据点。使用 countourf() 方法创建一个彩色的 3D(类似)图。使用 set_over() 方法,当“norm.clip = False”时,设置高超出范围值的颜色。使用 set_under() 方法,当“norm.clip = False”时,设置低超出范围值的颜色。使用 changed() 方法,每当可映射对象更改时调用此方法,以通知所有回调 SM 侦听器“changed”信号。使用 show() 方法显示图形。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = ... 阅读更多

如何在 matplotlib mplot3D 或类似的库中显示 3D 数组等值面的 3D 图?

Rishikesh Kumar Rishi
更新于 2021年4月10日 07:31:20

891 阅读量

让我们来看一个例子,了解如何在 matplotlib 中显示 3D 数组等值面的 3D 图 -示例import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.arange(-5, 5, 0.25) y = np.arange(-5, 5, 0.25) x, y = np.meshgrid(x, y) h = x ** 2 + y ** 2 fig = plt.figure() ax = Axes3D(fig) ax.plot_surface(x, y, h, rstride=1, cstride=1, cmap=plt.cm.rainbow, linewidth=0, antialiased=False) plt.show()输出

如何将绘图保存为 RGB 格式的 numpy 数组?

Rishikesh Kumar Rishi
更新于 2021年4月10日 07:29:13

1K+ 阅读量

为了将绘图保存为 RGB 格式的 numpy 数组,我们可以采取以下步骤 -使用 numpy 创建 r、g 和 b 的随机数组。将 r、g 和 b(来自步骤 1)压缩以创建一个 rgb 元组列表。将 rgb 转换为 numpy 数组以绘制它。绘制 rgb 格式的 numpy 数组。在当前位置保存图形。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True r = np.random.rand(100) g = np.random.rand(100) b = np.random.rand(100) rgb = zip(r, g, b) arr = np.array([item for item in rgb]) plt.plot(arr) plt.savefig("myplot.png") ... 阅读更多

如何使用 Matplotlib 设置 Seaborn 箱线图的 Y 轴范围?

Rishikesh Kumar Rishi
更新于 2021年4月9日 13:12:01

9K+ 阅读量

为了设置 Seaborn 箱线图的 Y 轴范围,我们可以采取以下步骤 -使用 set_style() 方法设置绘图的美学风格。使用 load_dataset("tips") 加载数据集;需要互联网。使用 boxplot() 绘制箱线图以显示相对于类别的分布。要设置 Y 轴范围,请使用 ylim() 方法。要显示图形,请使用 show() 方法。示例from matplotlib import pyplot as plt import seaborn as sns plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True sns.set_style("whitegrid") tips = sns.load_dataset("tips") ax = sns.boxplot(x="day", y="total_bill", data=tips) plt.ylim(5, 50) plt.show()输出阅读更多

使用 Matplotlib 在绘图上写入数值

Rishikesh Kumar Rishi
更新于 2021年4月9日 13:09:22

712 阅读量

为了在绘图上写入数值,我们可以采取以下步骤 -使用 numpy 创建 x 和 y 的点。使用 xpoints 创建标签。使用 scatter() 方法散布点。迭代标签、xpoints 和 ypoints,并使用不同的属性用标签、x 和 y 注释绘图。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True xpoints = np.linspace(1, 10, 25) ypoints = np.random.rand(25) labels = ["%.2f" % i for i in xpoints] plt.scatter(xpoints, ypoints, c=xpoints) for label, x, y in zip(labels, xpoints, ypoints):    plt.annotate(   ... 阅读更多

广告

© . All rights reserved.