当前位置: 首页 > news >正文

【python】matplotlib(animation)

在这里插入图片描述

文章目录

  • 1、matplotlib.animation
    • 1.1、FuncAnimation
    • 1.2、修改 matplotlib 背景
  • 2、matplotlib + imageio
    • 2.1、折线图
    • 2.2、条形图
    • 2.3、散点图
  • 3、参考

1、matplotlib.animation

1.1、FuncAnimation

matplotlib.animation.FuncAnimation 是 Matplotlib 库中用于创建动画的一个类。它允许你通过循环调用一个函数来更新图表,从而生成动画效果。这个函数通常被称为“更新函数”,它决定了每一帧图表的样子。FuncAnimation 类提供了一种灵活而强大的方式来创建和展示动画,使得数据可视化更加生动和直观。

(1)基本用法

使用 FuncAnimation 创建动画的基本步骤如下:

  • 准备数据:首先,你需要准备好用于动画的数据。这可能包括一系列的X和Y坐标点、颜色、大小等,具体取决于你要制作的动画类型。
  • 创建图形和轴:使用 Matplotlib 创建图形(Figure)和轴(Axes)对象,这些对象将作为动画的画布。
  • 定义更新函数:编写一个函数,这个函数接受当前的帧号(或其他参数)作为输入,并返回一个更新后的图形元素状态。例如,如果你正在制作一个点的移动动画,这个函数可能会更新点的位置。
  • 创建 FuncAnimation 对象:使用 FuncAnimation 类创建一个动画对象。你需要指定图形对象、轴对象、更新函数、帧数(或时间间隔)、以及其他可选参数(如重复次数、初始延迟等)。
  • 显示或保存动画:最后,你可以使用 Matplotlib 的显示功能(如 plt.show())来查看动画,或者将其保存为文件(如GIF、MP4等)。

(2)示例代码

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation# 准备数据
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)# 创建图形和轴
fig, ax = plt.subplots()
line, = ax.plot([], [], 'r-')  # 初始化一个空线条对象
ax.set_xlim(0, 2 * np.pi)      # 设置X轴范围
ax.set_ylim(-1.5, 1.5)         # 设置Y轴范围# 定义更新函数
def update(frame):line.set_data(x[:frame], y[:frame])  # 更新线条数据return line,# 创建 FuncAnimation 对象
ani = FuncAnimation(fig, update, frames=len(x), interval=50, blit=True)# 显示动画
plt.show()

在这里插入图片描述

在这个例子中,update 函数根据当前的帧号(frame)更新线条的数据,使得线条逐渐变长,模拟了一个点沿正弦曲线移动的动画效果。

再看一个例子

#coding=utf-8
import sysimport numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animationfig, ax = plt.subplots()x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))def animate(i):line.set_ydata(np.sin(x + i/10.0))return line,def init():line.set_ydata(np.ma.array(x, mask=True))return line,ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,interval=25, blit=True)
ani.save("animation.gif", writer="imagemagick", fps=30)
plt.show()

在这里插入图片描述

(3)matplotlib.animation.FuncAnimation

class matplotlib.animation.FuncAnimation(fig, func, frames=None, init_func=None, fargs=None, save_count=None, *, cache_frame_data=True, **kwargs)
def __init__(self,fig: Figure,func: (...) -> Iterable[Artist],frames: Iterable | int | () -> Generator | None = ...,init_func: () -> Iterable[Artist] | None = ...,fargs: tuple[Any, ...] | None = ...,save_count: int | None = ...,*,cache_frame_data: bool = ...,**kwargs: Any) -> None
`TimedAnimation` subclass that makes an animation by repeatedly calling a function *func*.  .. note::  You must store the created Animation in a variable that lives as long as the animation should run. Otherwise, the Animation object will be garbage-collected and the animation stops.  Parameters ---------- fig : `~matplotlib.figure.Figure` The figure object used to get needed events, such as draw or resize.  func : callable The function to call at each frame. The first argument will be the next value in *frames*. Any additional positional arguments can be supplied using `functools.partial` or via the *fargs* parameter.  The required signature is::  def func(frame, *fargs) -> iterable_of_artists  It is often more convenient to provide the arguments using `functools.partial`. In this way it is also possible to pass keyword arguments. To pass a function with both positional and keyword arguments, set all arguments as keyword arguments, just leaving the *frame* argument unset::  def func(frame, art, *, y=None): ...  ani = FuncAnimation(fig, partial(func, art=ln, y='foo'))  If ``blit == True``, *func* must return an iterable of all artists that were modified or created. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if ``blit == False`` and may be omitted in that case.  frames : iterable, int, generator function, or None, optional Source of data to pass *func* and each frame of the animation  - If an iterable, then simply use the values provided. If the iterable has a length, it will override the *save_count* kwarg.  - If an integer, then equivalent to passing ``range(frames)``  - If a generator function, then must have the signature::  def gen_function() -> obj  - If *None*, then equivalent to passing ``itertools.count``.  In all of these cases, the values in *frames* is simply passed through to the user-supplied *func* and thus can be of any type.  init_func : callable, optional A function used to draw a clear frame. If not given, the results of drawing from the first item in the frames sequence will be used. This function will be called once before the first frame.  The required signature is::  def init_func() -> iterable_of_artists  If ``blit == True``, *init_func* must return an iterable of artists to be re-drawn. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if ``blit == False`` and may be omitted in that case.  fargs : tuple or None, optional Additional arguments to pass to each call to *func*. Note: the use of `functools.partial` is preferred over *fargs*. See *func* for details.  save_count : int, optional Fallback for the number of values from *frames* to cache. This is only used if the number of frames cannot be inferred from *frames*, i.e. when it's an iterator without length or a generator.  interval : int, default: 200 Delay between frames in milliseconds.  repeat_delay : int, default: 0 The delay in milliseconds between consecutive animation runs, if *repeat* is True.  repeat : bool, default: True Whether the animation repeats when the sequence of frames is completed.  blit : bool, default: False Whether blitting is used to optimize drawing. Note: when using blitting, any animated artists will be drawn according to their zorder; however, they will be drawn on top of any previous artists, regardless of their zorder.  cache_frame_data : bool, default: True Whether frame data is cached. Disabling cache might be helpful when frames contain large objects.
Params:
fig – The figure object used to get needed events, such as draw or resize.
func – The function to call at each frame. The first argument will be the next value in *frames*. Any additional positional arguments can be supplied using `functools.partial` or via the *fargs* parameter. The required signature is:: def func(frame, *fargs) -> iterable_of_artists It is often more convenient to provide the arguments using `functools.partial`. In this way it is also possible to pass keyword arguments. To pass a function with both positional and keyword arguments, set all arguments as keyword arguments, just leaving the *frame* argument unset:: def func(frame, art, *, y=None): ... ani = FuncAnimation(fig, partial(func, art=ln, y='foo')) If ``blit == True``, *func* must return an iterable of all artists that were modified or created. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if ``blit == False`` and may be omitted in that case.
frames – Source of data to pass *func* and each frame of the animation - If an iterable, then simply use the values provided. If the iterable has a length, it will override the *save_count* kwarg. - If an integer, then equivalent to passing ``range(frames)`` - If a generator function, then must have the signature:: def gen_function() -> obj - If *None*, then equivalent to passing ``itertools.count``. In all of these cases, the values in *frames* is simply passed through to the user-supplied *func* and thus can be of any type.
init_func – A function used to draw a clear frame. If not given, the results of drawing from the first item in the frames sequence will be used. This function will be called once before the first frame. The required signature is:: def init_func() -> iterable_of_artists If ``blit == True``, *init_func* must return an iterable of artists to be re-drawn. This information is used by the blitting algorithm to determine which parts of the figure have to be updated. The return value is unused if ``blit == False`` and may be omitted in that case.
fargs – Additional arguments to pass to each call to *func*. Note: the use of `functools.partial` is preferred over *fargs*. See *func* for details.
save_count – Fallback for the number of values from *frames* to cache. This is only used if the number of frames cannot be inferred from *frames*, i.e. when it's an iterator without length or a generator.
cache_frame_data – Whether frame data is cached. Disabling cache might be helpful when frames contain large objects.
  • fig:图形对象(Figure),用于获取绘制、调整大小等事件。这是动画的画布。
  • func:可调用对象(函数),每帧调用的函数。该函数的第一个参数将是 frames 中的下一个值。任何其他的位置参数可以通过 fargs 参数提供。如果 blit 为 True,则该函数必须返回一个被修改或创建的所有图形元素(artists)的可迭代对象。
  • frames:可迭代对象、整数、生成器函数或 None,可选。用于传递给 func 和动画的每一帧的数据源。如果是可迭代对象,则直接使用提供的值。如果是一个整数,则相当于传递 range(frames)。如果是一个生成器函数,则必须具有特定的签名。如果为 None,则相当于传递 itertools.count。
  • init_func:可调用对象(函数),可选。用于绘制清空画面的函数。如果未提供,则将使用 frames 序列中的第一个项目的绘图结果。此函数将在第一帧之前被调用一次。如果 blit 为 True,则 init_func 必须返回一个将被重新绘制的图形元素(artists)的可迭代对象。
  • fargs:元组或 None,可选。传递给每次调用 func 的附加参数。
  • save_count:整数,可选。要缓存的 frames 中的值的数量。
  • interval:数字,可选。帧之间的延迟时间(以毫秒为单位)。默认为 200。
  • blit:布尔值,可选。控制是否使用 blitting 来优化绘制。当使用 blitting 时,只有变化的图形元素会被重新绘制,从而提高性能。
  • cache_frame_data:布尔值,可选。控制是否缓存帧数据。默认为 True。

方法说明

  • save:将动画保存为电影文件。
  • to_html5_video:将动画转换为 HTML5 视频。
  • to_jshtml:生成动画的 HTML 表示形式。

(4)注意事项

  • 性能:对于复杂的动画,可能需要优化性能,比如通过减少每次更新的数据量(使用 blit=True 参数)或调整帧的更新间隔。
  • 兼容性:保存动画时,不同的文件格式(如GIF、MP4)可能需要不同的编解码器支持。确保你的环境中安装了必要的编解码器。
  • 交互性:动画在Jupyter Notebook等交互式环境中可能表现不同,需要根据具体环境调整显示方式。

1.2、修改 matplotlib 背景

在上述示例代码的情况下,我们引入一些修改颜色的配置,

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation# 准备数据
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)# 创建图形和轴
fig, ax = plt.subplots()
line, = ax.plot([], [], 'r-')  # 初始化一个空线条对象
ax.set_xlim(0, 2 * np.pi)  # 设置X轴范围
ax.set_ylim(-1.5, 1.5)  # 设置Y轴范围# 修改轴背景颜色
ax.set_facecolor("orange")  
# OR
# ax.set(facecolor = "orange")# 修改绘图背景颜色
fig.patch.set_facecolor('yellow')   
fig.patch.set_alpha(1.0)# 移除图表的上边框和右边框
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)# 设置虚线网格线
ax.set_axisbelow(True)
ax.yaxis.grid(color='gray', linestyle='dashed', alpha=0.7)# 定义更新函数
def update(frame):line.set_data(x[:frame], y[:frame])  # 更新线条数据return line,# 创建 FuncAnimation 对象
ani = FuncAnimation(fig, update, frames=len(x), interval=50, blit=True)# ani.save("animation.gif", writer="imagemagick", fps=30)# 显示动画
plt.show()

修改前

在这里插入图片描述

修改后
在这里插入图片描述
换个背景图试试

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation# 准备数据
x = np.linspace(0, 20 * np.pi, 100)
y = 9* np.sin(x)# 创建图形和轴
fig, ax = plt.subplots()
line, = ax.plot([], [], 'r-')  # 初始化一个空线条对象img = plt.imread("123.jpg")
ax.imshow(img, extent=[0, 65, -10, 10])  # 横纵坐标范围# 定义更新函数
def update(frame):line.set_data(x[:frame], y[:frame])  # 更新线条数据return line,# 创建 FuncAnimation 对象
ani = FuncAnimation(fig, update, frames=len(x), interval=50, blit=True)ani.save("animation.gif", writer="imagemagick", fps=30)# 显示动画
plt.show()

原始图片

在这里插入图片描述

添加之后的效果
在这里插入图片描述

2、matplotlib + imageio

2.1、折线图

先画个简单的折线图

import os
import numpy as np
import matplotlib.pyplot as plt
import imageionp.random.seed(1234)# 生成40个取值在30-40的数
y = np.random.randint(30, 40, size=(40))
print(y)
"""
[33 36 35 34 38 39 31 37 39 36 38 30 35 30 39 36 32 30 35 32 36 33 37 3039 30 33 32 33 31 33 31 33 37 31 37 34 30 35 31]
"""
# 绘制折线
plt.plot(y)
# 设置y轴最小值和最大值
plt.ylim(20, 50)# 显示
plt.show()

在这里插入图片描述

保存最后几个点的数据,然后绘制成 gif

import os
import numpy as np
import matplotlib.pyplot as plt
import imageionp.random.seed(1234)# 生成40个取值在30-40的数
y = np.random.randint(30, 40, size=(40))
print(y)
"""
[33 36 35 34 38 39 31 37 39 36 38 30 35 30 39 36 32 30 35 32 36 33 37 3039 30 33 32 33 31 33 31 33 37 31 37 34 30 35 31]
"""
# 绘制折线
plt.plot(y)
# 设置y轴最小值和最大值
plt.ylim(20, 50)# 显示
plt.show()# 第一张图
plt.plot(y[:-3])
plt.ylim(20, 50)
plt.savefig('1.png')
plt.show()# 第二张图
plt.plot(y[:-2])
plt.ylim(20, 50)
plt.savefig('2.png')
plt.show()# 第三张图
plt.plot(y[:-1])
plt.ylim(20, 50)
plt.savefig('3.png')
plt.show()# 第四张图
plt.plot(y)
plt.ylim(20, 50)
plt.savefig('4.png')
plt.show()# 生成Gif
with imageio.get_writer('mygif.gif', mode='I') as writer:for filename in ['1.png', '2.png', '3.png', '4.png']:image = imageio.imread(filename)writer.append_data(image)

横坐标 0 至 36
在这里插入图片描述

横坐标 0 至 37

在这里插入图片描述

横坐标 0 至 38

在这里插入图片描述

横坐标 0 至 39

在这里插入图片描述

合并成为 gif(仅播放一次)

请添加图片描述

下面把所有点都保存下来,绘制动态图(仅播放一次)

import os
import numpy as np
import matplotlib.pyplot as plt
import imageionp.random.seed(1234)# 生成40个取值在30-40的数
y = np.random.randint(30, 40, size=(40))
print(y)
"""
[33 36 35 34 38 39 31 37 39 36 38 30 35 30 39 36 32 30 35 32 36 33 37 3039 30 33 32 33 31 33 31 33 37 31 37 34 30 35 31]
"""
# 绘制折线
plt.plot(y)
# 设置y轴最小值和最大值
plt.ylim(20, 50)# 显示
plt.show()filenames = []
num = 0
for i in y:num += 1# 绘制40张折线图plt.plot(y[:num])plt.ylim(20, 50)# 保存图片文件filename = f'{num}.png'filenames.append(filename)plt.savefig(filename)plt.close()# 生成gif
with imageio.get_writer('mygif.gif', mode='I') as writer:for filename in filenames:image = imageio.imread(filename)writer.append_data(image)# 删除40张折线图
for filename in set(filenames):os.remove(filename)

在这里插入图片描述

2.2、条形图

import os
import numpy as np
import matplotlib.pyplot as plt
import imageionp.random.seed(1234)x = [1, 2, 3, 4, 5]
coordinates_lists = [[0, 0, 0, 0, 0],[10, 30, 60, 30, 10],[70, 40, 20, 40, 70],[10, 20, 30, 40, 50],[50, 40, 30, 20, 10],[75, 0, 75, 0, 75],[0, 0, 0, 0, 0]]
filenames = []
for index, y in enumerate(coordinates_lists):# 条形图plt.bar(x, y)plt.ylim(0, 80)# 保存图片文件filename = f'{index}.png'filenames.append(filename)# 重复最后一张图形15帧(数值都为0),15张图片if (index == len(coordinates_lists) - 1):for i in range(15):filenames.append(filename)# 保存plt.savefig(filename)plt.close()# 生成gif
with imageio.get_writer('mygif.gif', mode='I') as writer:for filename in filenames:image = imageio.imread(filename)writer.append_data(image)# 删除20张柱状图
for filename in set(filenames):os.remove(filename)

生成的图片

在这里插入图片描述

生成的 gif(播放一次)

在这里插入图片描述

看起来太快了,优化代码使其平滑

import os
import numpy as np
import matplotlib.pyplot as plt
import imageionp.random.seed(1234)n_frames = 10  # 怕内存不够的话可以设置小一些
x = [1, 2, 3, 4, 5]
coordinates_lists = [[0, 0, 0, 0, 0],[10, 30, 60, 30, 10],[70, 40, 20, 40, 70],[10, 20, 30, 40, 50],[50, 40, 30, 20, 10],[75, 0, 75, 0, 75],[0, 0, 0, 0, 0]]
print('生成图表\n')
filenames = []
for index in np.arange(0, len(coordinates_lists) - 1):# 获取当前图像及下一图像的y轴坐标值y = coordinates_lists[index]y1 = coordinates_lists[index + 1]# 计算当前图像与下一图像y轴坐标差值y_path = np.array(y1) - np.array(y)for i in np.arange(0, n_frames + 1):# 分配每帧的y轴移动距离# 逐帧增加y轴的坐标值y_temp = (y + (y_path / n_frames) * i)# 绘制条形图plt.bar(x, y_temp)plt.ylim(0, 80)# 保存每一帧的图像filename = f'frame_{index}_{i}.png'filenames.append(filename)# 最后一帧重复,画面停留一会if (i == n_frames):for i in range(5):filenames.append(filename)# 保存图片plt.savefig(filename)plt.close()
print('保存图表\n')# 生成GIF
print('生成GIF\n')
with imageio.get_writer('mybars.gif', mode='I') as writer:for filename in filenames:image = imageio.imread(filename)writer.append_data(image)
print('保存GIF\n')print('删除图片\n')
# 删除图片
for filename in set(filenames):os.remove(filename)
print('完成')

原理解释统计柱状图当前帧和下一帧的差值,然后插帧平滑过去,这里插帧数量配置为了 n_frames = 10

最终生成的 gif 如下(仅播放一次),可以观察到平滑了很多
在这里插入图片描述

接下来美化下界面

import os
import numpy as np
import matplotlib.pyplot as plt
import imageionp.random.seed(1234)n_frames = 5
bg_color = '#95A4AD'
bar_color = '#283F4E'
gif_name = 'bars'
x = [1, 2, 3, 4, 5]
coordinates_lists = [[0, 0, 0, 0, 0],[10, 30, 60, 30, 10],[70, 40, 20, 40, 70],[10, 20, 30, 40, 50],[50, 40, 30, 20, 10],[75, 0, 75, 0, 75],[0, 0, 0, 0, 0]]
print('生成图表\n')
filenames = []
for index in np.arange(0, len(coordinates_lists) - 1):y = coordinates_lists[index]y1 = coordinates_lists[index + 1]y_path = np.array(y1) - np.array(y)for i in np.arange(0, n_frames + 1):y_temp = (y + (y_path / n_frames) * i)# 绘制条形图fig, ax = plt.subplots(figsize=(8, 4))ax.set_facecolor(bg_color)plt.bar(x, y_temp, width=0.4, color=bar_color)plt.ylim(0, 80)# 移除图表的上边框和右边框ax.spines['right'].set_visible(False)ax.spines['top'].set_visible(False)# 设置虚线网格线ax.set_axisbelow(True)ax.yaxis.grid(color='gray', linestyle='dashed', alpha=0.7)# 保存每一帧的图像filename = f'images/frame_{index}_{i}.png'filenames.append(filename)# 最后一帧重复,画面停留一会if (i == n_frames):for i in range(5):filenames.append(filename)# 保存图片plt.savefig(filename, dpi=96, facecolor=bg_color)plt.close()
print('保存图表\n')# 生成GIF
print('生成GIF\n')
with imageio.get_writer(f'{gif_name}.gif', mode='I') as writer:for filename in filenames:image = imageio.imread(filename)writer.append_data(image)
print('保存GIF\n')print('删除图片\n')
# 删除图片
for filename in set(filenames):os.remove(filename)
print('完成')

看看生成的 gif 效果(仅播放一次)

在这里插入图片描述
给图表添加了背景色、条形图上色、去除边框、增加网格线等。

2.3、散点图

import os
import numpy as np
import matplotlib.pyplot as plt
import imageionp.random.seed(1234)coordinates_lists = [[[0], [0]],[[100, 200, 300], [100, 200, 300]],[[400, 500, 600], [400, 500, 600]],[[400, 500, 600, 400, 500, 600], [400, 500, 600, 600, 500, 400]],[[500], [500]],[[0], [0]]]
gif_name = 'movie'
n_frames = 5
bg_color = '#95A4AD'
marker_color = '#283F4E'
marker_size = 25print('生成图表\n')
filenames = []
for index in np.arange(0, len(coordinates_lists) - 1):# 获取当前图像及下一图像的x与y轴坐标值x = coordinates_lists[index][0]  # 当前帧y = coordinates_lists[index][1]x1 = coordinates_lists[index + 1][0]  # 下一帧y1 = coordinates_lists[index + 1][1]# 查看两点差值while len(x) < len(x1):diff = len(x1) - len(x)x = x + x[:diff]y = y + y[:diff]while len(x1) < len(x):diff = len(x) - len(x1)x1 = x1 + x1[:diff]y1 = y1 + y1[:diff]# 计算路径x_path = np.array(x1) - np.array(x)y_path = np.array(y1) - np.array(y)for i in np.arange(0, n_frames + 1):# 计算当前位置x_temp = (x + (x_path / n_frames) * i)y_temp = (y + (y_path / n_frames) * i)# 绘制图表fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(aspect="equal"))ax.set_facecolor(bg_color)plt.scatter(x_temp, y_temp, c=marker_color, s=marker_size)plt.xlim(0, 1000)plt.ylim(0, 1000)# 移除边框线ax.spines['right'].set_visible(False)ax.spines['top'].set_visible(False)# 网格线ax.set_axisbelow(True)ax.yaxis.grid(color='gray', linestyle='dashed', alpha=0.7)ax.xaxis.grid(color='gray', linestyle='dashed', alpha=0.7)# 保存图片filename = f'images/frame_{index}_{i}.png'filenames.append(filename)if (i == n_frames):for i in range(5):filenames.append(filename)# 保存plt.savefig(filename, dpi=96, facecolor=bg_color)plt.close()
print('保存图表\n')# 生成GIF
print('生成GIF\n')
with imageio.get_writer(f'{gif_name}.gif', mode='I') as writer:for filename in filenames:image = imageio.imread(filename)writer.append_data(image)
print('保存GIF\n')print('删除图片\n')
# 删除图片
for filename in set(filenames):os.remove(filename)
print('完成')

思路,计算前后帧坐标点数量的差 diff ,然后 while 循环来复制以实现数量平衡 x = x + x[:diff],最后插帧平滑移动 x_temp = (x + (x_path / n_frames) * i)

在这里插入图片描述

3、参考

  • 太强了,用 Matplotlib+Imageio 制作动画!
  • 如何在 Matplotlib 中更改绘图背景

相关文章:

【python】matplotlib(animation)

文章目录 1、matplotlib.animation1.1、FuncAnimation1.2、修改 matplotlib 背景 2、matplotlib imageio2.1、折线图2.2、条形图2.3、散点图 3、参考 1、matplotlib.animation 1.1、FuncAnimation matplotlib.animation.FuncAnimation 是 Matplotlib 库中用于创建动画的一个…...

【Linux网络编程】之守护进程

【Linux网络编程】之守护进程 进程组进程组的概念组长进程 会话会话的概念会话ID 控制终端控制终端的概念控制终端的作用会话、终端、bash三者的关系 前台进程与后台进程概念特点查看当前终端的后台进程前台进程与后台进程的切换 作业控制相关概念作业状态&#xff08;一般指后…...

Vue.js如何根据访问路径切换页面

Vue Router 在前端工程中&#xff0c;路由指的是&#xff0c;根据不同的访问路径&#xff0c;展示不同组件的内容。 Vue Router是Vue.js的官方路由。 Vue Router介绍。 要使用vue Router&#xff0c;得先安装 npm install vue-router4这里的4&#xff0c;指的是第4个版本 在s…...

Vue与Konva:解锁Canvas绘图的无限可能

前言 在现代Web开发中&#xff0c;动态、交互式的图形界面已成为提升用户体验的关键要素。Vue.js&#xff0c;作为一款轻量级且高效的前端框架&#xff0c;凭借其响应式数据绑定和组件化开发模式&#xff0c;赢得了众多开发者的青睐。而当Vue.js邂逅Konva.js&#xff0c;两者结…...

collabora online+nextcloud+mariadb在线文档协助

1、环境 龙蜥os 8.9 docker 2、安装docker dnf -y install dnf-plugins-core dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sed -i shttps://download.docker.comhttps://mirrors.tuna.tsinghua.edu.cn/docker-ce /etc/yum.repos.…...

linux基础命令1

1、linux目录结构——树型结构 根目录&#xff1a;/ 用户主目录(家目录)&#xff1a;~或者 /home/edu 根目录下常见的文件夹: 2、常见的命令 1、pwd 查看当前目录 cd 切换目录 cd ~ 切换到家目录 2、ls 查看当前目录的文件信息 语法:ls [选项] [参…...

[LVGL] 在VC_MFC中移植LVGL

前言&#xff1a; 0. 在MFC中开发LVGL的优点是可以用多个Window界面做辅助扩展【类似GUIguider】 1.本文基于VC2022-MFC单文档框架移植lvgl8 2. gitee上下载lvgl8.3 源码&#xff0c;并将其文件夹改名为lvgl lvgl: LVGL 是一个开源图形库&#xff0c;提供您创建具有易于使用…...

Spring Boot整合MQTT

MQTT是基于代理的轻量级的消息发布订阅传输协议。 1、下载安装代理 进入mosquitto下载地址&#xff1a;Download | Eclipse Mosquitto&#xff0c;进行下载&#xff0c;以win版本为例 下载完成后&#xff0c;在本地文件夹找到下载的代理安装文件 使用管理员身份打开安装 安装…...

elasticsearch实战三 elasticsearch与mysql数据实时同步

一 介绍 elasticsearch数据不是一直不变的&#xff0c;需要与mysql、oracle等数据库的数据做同步。 本博客里涉及到的项目地址&#xff1a;https://www.aliyundrive.com/s/7bRWpTYsxWV 方案一&#xff1a; 同步调用&#xff0c;即操作mysql数据后&#xff0c;接着操作elastic…...

netcore openTelemetry+prometheus+grafana

一、netcore项目 二、openTelemetry 三、prometheus 四、grafana添加Dashborad aspire/src/Grafana/dashboards at main dotnet/aspire GitHub 导入&#xff1a;aspnetcore.json和aspnetcore-endpoint.json 效果&#xff1a;...

StochSync:可在任意空间中生成360°全景图和3D网格纹理

StochSync方法可以用于在任意空间中生成图像&#xff0c;尤其是360全景图和3D网格纹理。该方法利用了预训练的图像扩散模型&#xff0c;以实现零-shot生成&#xff0c;消除了对新数据收集和单独训练生成模型的需求。StochSync 结合了 Diffusion Synchronization&#xff08;DS&…...

MybatisPlus较全常用复杂查询引例(limit、orderby、groupby、having、like...)

MyBatis-Plus 是一个 MyBatis 的增强工具&#xff0c;在 MyBatis 的基础上只做增强不做改变&#xff0c;为简化开发、提高效率而生。以下是 MyBatis-Plus 中常用复杂查询&#xff08;如 LIMIT、ORDER BY、GROUP BY、HAVING、LIKE 等&#xff09;的引例&#xff1a; 1. 环境准备…...

大数据项目2:基于hadoop的电影推荐和分析系统设计和实现

前言 大数据项目源码资料说明&#xff1a; 大数据项目资料来自我多年工作中的开发积累与沉淀。 我分享的每个项目都有完整代码、数据、文档、效果图、部署文档及讲解视频。 可用于毕设、课设、学习、工作或者二次开发等&#xff0c;极大提升效率&#xff01; 1、项目目标 本…...

win10的Unet项目导入阿里云训练

win10配置文件 annotated-types0.7.0 certifi2024.12.14 charset-normalizer3.4.1 click8.1.8 colorama0.4.6 contourpy1.1.1 cycler0.12.1 docker-pycreds0.4.0 eval_type_backport0.2.2 filelock3.16.1 fonttools4.55.3 fsspec2024.12.0 gitdb4.0.12 GitPython3.1.44 idna3.…...

Linux(20)——调度作业

目录 一、调度延迟的用户作业&#xff1a; 1、延迟的用户作业&#xff1a; 2、查看延迟的用户作业&#xff1a; 3、从计划中删除作业&#xff1a; 二、调度周期性用户作业&#xff1a; 1、周期性用户作业&#xff1a; 2、调度周期性用户作业&#xff1a; 3、用户作业格…...

DeepSeek赋能Vue:打造超丝滑进度条开发指南

前言&#xff1a;哈喽&#xff0c;大家好&#xff0c;今天给大家分享一篇文章&#xff01;并提供具体代码帮助大家深入理解&#xff0c;彻底掌握&#xff01;创作不易&#xff0c;如果能帮助到大家或者给大家一些灵感和启发&#xff0c;欢迎收藏关注哦 &#x1f495; 目录 Deep…...

在CT107D单片机综合训练平台上,8个数码管分别单独依次显示0~9的值,然后所有数码管一起同时显示0~F的值,如此往复。

题目&#xff1a;在CT107D单片机综合训练平台上&#xff0c;8个数码管分别单独依次显示0~9的值&#xff0c;然后所有数码管一起同时显示0~F的值&#xff0c;如此往复。 延时函数分析LED首先实现8个数码管单独依次显示0~9的数字所有数码管一起同时显示0~F的值&#xff0c;如此往…...

清除el-table选中状态 clearSelection

如何在Vue应用中使用Element UI的el-table组件&#xff0c;通过this.$refs.multipleTable.clearSelection()方法来清除所有选中行的状态。适合前端开发者了解表格组件的交互操作。 // el-table绑定ref<el-table selection-change"selsChange" ref"multipl…...

【算法】动态规划专题⑥ —— 完全背包问题 python

目录 前置知识进入正题模板 前置知识 【算法】动态规划专题⑤ —— 0-1背包问题 滚动数组优化 完全背包问题是动态规划中的一种经典问题&#xff0c;它与0-1背包问题相似&#xff0c;但有一个关键的区别&#xff1a;在完全背包问题中&#xff0c;每种物品都有无限的数量可用。…...

论文笔记-COLING2025-LLMTreeRec

论文笔记-COLING2025-LLMTreeRec: Unleashing the Power of Large Language Models for Cold-Start Recommendations LLMTreeRec: 释放大语言模型在冷启动推荐中的力量摘要1.引言2.框架2.1项目树构建2.2以LLM为中心的基于树的推荐2.2.1推荐链策略2.2.2检索策略 3.实验3.1实验设…...

c++ haru生成pdf输出饼图

#define PI 3.14159265358979323846 // 绘制饼图的函数 void draw_pie_chart(HPDF_Doc pdf, HPDF_Page page, float *data, int data_count, float x, float y, float radius) { float total 0; int i; // 计算数据总和 for (i 0; i < data_count; i) { tot…...

【‌Unity】Unity中物体的static属性作用

‌Unity中物体的static属性主要用于优化游戏性能和简化渲染过程。‌ Unity中物体的static属性的作用 优化渲染性能‌&#xff1a;当物体被标记为static时&#xff0c;Unity会在游戏运行时将其视为静止的物体&#xff0c;这意味着这些物体的渲染信息不会随着每一帧的更新而变化…...

Rust 测试指南:从入门到进阶

1. 测试基础&#xff1a;#[test] 属性 Rust 测试的基本单位是函数。只要在一个函数前面标注 #[test] 属性&#xff0c;那么在运行 cargo test 时&#xff0c;Rust 会自动识别并执行它。例如&#xff0c;新建一个库工程 adder&#xff0c;cargo new adder --lib&#xff0c;在 …...

Elasticsearch 生产集群部署终极方案

Elasticsearch 集群部署 1.集群部署1.1 新增用户1.2 优化操作系统1.3 JDK1.4 elasticsearch1.5 开机自启动 2.安全认证功能2.1 生成CA证书2.2 生成密钥2.3 上传至其他节点2.4 修改属主、属组2.5 配置文件添加参数2.6 各节点添加密钥库密码2.7 设置用户密码 1.集群部署 1.1 新增…...

电路笔记(元器件):AD 5263数字电位计(暂记)

AD5263 是四通道、15 V、256位数字电位计&#xff0c;可通过SPI/I2C配置具体电平值。 配置模式&#xff1a; W引脚作为电位器的抽头&#xff0c;可在A-B之间调整任意位置的电阻值。也可将W与A(或B)引脚短接&#xff0c;A-W间的电阻总是0欧姆&#xff0c;通过数字接口调整电位器…...

如何在电脑后台定时进行自动截图?自动截图后如何快捷保存?如何远程查看?

7-2 有时候需要对电脑的屏幕进行在后台连续性的截图保存&#xff0c;并且要可以远程查看&#xff0c;无界面&#xff0c;以达到对电脑的使用过程进行完全了解的目的&#xff0c;一般用于对小孩使用电脑的掌握&#xff0c;如果父母在外地&#xff0c;不方便就近管理&#xff0c…...

解决react中函数式组件usestate异步更新

问题&#xff1a;在点击modal组件确认后 调用后端接口&#xff0c;使用setstateone&#xff08;false&#xff09;使modal组件关闭&#xff0c;但是设置后关闭不了&#xff0c;在设置setstateone&#xff08;false&#xff09;前后打印出了对应的stateone都为true&#xff0c;但…...

skia-macos源码编译

1、下载git-hub 源码 2、下载依赖库 3、编译&#xff0c;注意选项 bin/gn gen out/release --args"is_official_buildfalse skia_use_system_expatfalse skia_use_system_icufalse skia_use_libjpeg_turbofalse skia_use_system_libpngfalse skia_use_system_libwebpfal…...

本地部署DeepSeek(Mac版本,带图形化操作界面)

一、下载安装&#xff1a;Ollama 官网下载&#xff1a;Download Ollama on macOS 二、安装Ollama 1、直接解压zip压缩包&#xff0c;解压出来就是应用程序 2、直接将Ollama拖到应用程序中即可 3、启动终端命令验证 # 输入 ollama 代表已经安装成功。 4、下载模型 点击模型…...

离线统信系统的python第三方库批量安装流程

一、关于UOS本机 操作系统&#xff1a;UOS&#xff08;基于Debian的Linux发行版&#xff09; CPU&#xff1a;海光x86 二、具体步骤 1、在联网的电脑上用控制台的pip命令批量下载指定版本的第三方库 方法A cd <目标位置的绝对路径> pip download -d . --platform many…...

群晖安装Gitea

安装Docker Docker运行Gitea 上传gitea包&#xff0c;下载地址&#xff1a;https://download.csdn.net/download/hmxm6/90360455 打开docker 点击印象&#xff0c;点击新增&#xff0c;从文件添加 点击启动 可根据情况&#xff0c;进行高级设置&#xff0c;没有就下一步 点击应…...

jmeter逻辑控制器9

1&#xff0c;简单控制器2&#xff0c;录制控制器3&#xff0c;循环控制器4&#xff0c;随机控制器5&#xff0c;随机顺序控制器6&#xff0c;if控制器7&#xff0c;模块控制器8&#xff0c;Include控制器9&#xff0c;事物控制器本文永久更新地址: 1&#xff0c;简单控制器 不…...

Spring统一修改RequestBody

我们编写RestController时&#xff0c;有可能多个接口使用了相同的RequestBody&#xff0c;在一些场景下需求修改传入的RequestBody的值&#xff0c;如果是每个controller中都去修改&#xff0c;代码会比较繁琐&#xff0c;最好的方式是在一个地方统一修改&#xff0c;比如将he…...

自动化xpath定位元素(附几款浏览器xpath插件)

在 Web 自动化测试、数据采集、前端调试中&#xff0c;XPath 仍然是不可或缺的技能。虽然 CSS 选择器越来越强大&#xff0c;但面对复杂 DOM 结构时&#xff0c;XPath 仍然更具灵活性。因此&#xff0c;掌握 XPath&#xff0c;不仅能提高自动化测试的稳定性&#xff0c;还能在爬…...

go-elasticsearch创建ik索引并进行查询操作

es-go client引入gomod go get github.com/elastic/go-elasticsearch/v8latest连接es服务器&#xff08;不经过安全校验) cfg : elasticsearch.Config{Addresses: []string{"http://localhost:9200",}, } es, err : elasticsearch.NewClient(cfg) if err ! nil {pa…...

【东莞常平】戴尔R710服务器不开机维修分享

1&#xff1a;2025-02-06一位老客户的朋友刚开工公司ERP服务器一台戴尔老服务器故障无法开机&#xff0c;于是经老客户介绍找到我们。 2&#xff1a;服务器型号是DELL PowerEdge R710 这个服务器至少也有15年以上的使用年限了。 3&#xff1a;客户反馈的故障问题为&#xff1a;…...

rebase和merge

rebase 和merge区别&#xff1a; rebase变基&#xff0c;改变基底&#xff1a;rebase会抹去提交记录。 git pull 默认merge&#xff0c;git pull --rebase 变基 rebase C、D提交属于feature分支&#xff0c;是基于master分支&#xff0c;在B提交额外拉出来的&#xff0c;当…...

SSA-TCN麻雀算法优化时间卷积神经网络时间序列预测未来Matlab实现

SSA-TCN麻雀算法优化时间卷积神经网络时间序列预测未来Matlab实现 目录 SSA-TCN麻雀算法优化时间卷积神经网络时间序列预测未来Matlab实现预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.Matlab实现SSA-TCN麻雀算法优化时间卷积神经网络时间序列预测未来&#xff08;优…...

2025牛客寒假算法基础集训营5(补题)

C 小L的位运算 显然&#xff0c;如果两次反置的价格小于等于交换的价格&#xff0c;那么直接全部反置就好了。 反之&#xff0c;由于交换一定低于两次反置&#xff0c;我们尽可能用交换来消去不正确的位置。不正确的位置类型只有00&#xff0c;01&#xff0c;10&#xff0c;11&…...

Kotlin Android 环境搭建

Kotlin Android 环境搭建 引言 随着移动应用的日益普及,Android 开发成为了一个热门的技术领域。Kotlin 作为一种现代的编程语言,因其简洁、安全、互操作性强等特点,被越来越多的开发者所喜爱。本文将详细介绍 Kotlin Android 环境搭建的步骤,帮助您快速上手 Kotlin Andr…...

DeepSeek图解10页PDF

以前一直在关注国内外的一些AI工具&#xff0c;包括文本型、图像类的一些AI实践&#xff0c;最近DeepSeek突然爆火&#xff0c;从互联网收集一些资料与大家一起分享学习。 本章节分享的文件为网上流传的DeepSeek图解10页PDF&#xff0c;免费附件链接给出。 1 本地 1 本地部…...

Kafka中的KRaft算法

我们之前的Kafka值依赖于Zookeeper注册中心来启动的&#xff0c;往里面注册我们节点信息 Kafka是什么时候不依赖Zookeeper节点了 在Kafka2.8.0开始就可以不依赖Zookeeper了 可以用KRaft模式代替Zookeeper管理Kafka集群 KRaft Controller和KRaft Leader的关系 两者关系 Lea…...

C++20新特性

作者&#xff1a;billy 版权声明&#xff1a;著作权归作者所有&#xff0c;商业转载请联系作者获得授权&#xff0c;非商业转载请注明出处 前言 C20 是 C 标准中的一个重要版本&#xff0c;引入了许多新特性和改进&#xff0c;包括模块&#xff08;Modules&#xff09;、协程…...

[LUA ERROR] bad light userdata pointer

Cocos2d项目&#xff0c;targetSdkVersion30&#xff0c;在 android 13 设备运行报错: [LUA ERROR] bad light userdata pointer &#xff0c;导致黑屏。 参考 cocos2dx 适配64位 arm64-v8a 30 lua 提示 bad light userdata pointer 黑屏-CSDN博客的方法 下载最新的Cocos2dx …...

Maven 安装配置(完整教程)

文章目录 一、Maven 简介二、下载 Maven三、配置 Maven3.1 配置环境变量3.2 Maven 配置3.3 IDEA 配置 四、结语 一、Maven 简介 Maven 是一个基于项目对象模型&#xff08;POM&#xff09;的项目管理和自动化构建工具。它主要服务于 Java 平台&#xff0c;但也支持其他编程语言…...

JAVA:CloseableHttpClient 进行 HTTP 请求的技术指南

1、简述 CloseableHttpClient 是 Apache HttpComponents 提供的一个强大 HTTP 客户端库。它允许 Java 程序与 HTTP/HTTPS 服务交互&#xff0c;可以发送 GET、POST 等各种请求类型&#xff0c;并处理响应。该库广泛用于 REST API 调用、文件上传和下载等场景。 2、特性 Close…...

WebRTC 客户端与ZLMediaKit通讯

1 web浏览器js方式 要使用 WebRTC 客户端与 ZLMediaKit 通讯&#xff0c;您需要设置一个 WebRTC 客户端并与 ZLMediaKit 进行连接。以下是一个基本的步骤和示例代码&#xff0c;帮助您实现这一目标。 ### 步骤 1. **安装 ZLMediaKit**&#xff1a;确保您已经在服务器上安装并…...

openssl使用

openssl使用 提取密钥对 数字证书pfx包含公钥和私钥&#xff0c;而cer证书只包含公钥。提取需输入证书保护密码 openssl pkcs12 -in xxx.pfx -nocerts -nodes -out pare.key提取私钥 openssl rsa -in pare.key -out pri.key提取公钥 openssl rsa -in pare.key -pubout -ou…...

stm32小白成长为高手的学习步骤和方法

我们假定大家已经对STM32的书籍或者文档有一定的理解。如不理解&#xff0c;请立即阅读STM32的文档&#xff0c;以获取最基本的知识点。STM32单片机自学教程 这篇博文也是一篇不错的入门教程&#xff0c;初学者可以看看&#xff0c;讲的真心不错。 英文好的同学&#xf…...

支持多种网络数据库格式的自动化转换工具——VisualXML

一、VisualXML软件介绍 对于DBC、ARXML……文件的编辑、修改等繁琐操作&#xff0c;WINDHILL风丘科技开发的总线设计工具——VisualXML&#xff0c;可轻松解决这一问题&#xff0c;提升工作效率。 VisualXML是一个强大且基于Excel表格生成多种网络数据库文件的转换工具&#…...