首页 > 解决方案 > 如何在 matplotlib 图表的 x 轴下方添加徽标

问题描述

我想使用 matplotlib 在图表的右下角添加徽标。

我的标志不适合在正确的位置。

我的标志来源="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/vox.png"

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as image
import matplotlib.pyplot as plt#
from matplotlib.offsetbox import  OffsetImage
fig, ax = plt.subplots()
logo=image.imread("https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/vox.png")
# You have to add your own logo, this is in my own folder
addLogo = OffsetImage(logo, zoom=0.4)
#addLogo.set_zorder(100)
addLogo.set_offset((250,-25)) # pass the position in a tuple
ax.add_artist(addLogo)
height = [6, 10, 5, 18, 45]
bars = ('A', 'B', 'C', 'D', 'E')
y = np.arange(len(bars))
plt.bar(y, height, color=(0.2, 0.4, 0.6, 0.6))

在此处输入图像描述

在 jupyter notebook 中,logo 就像镜子一样。 在此处输入图像描述

标签: pythonmatplotlib

解决方案


推荐阅读