Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python 3 matplotlib添加具有多个缩放轴的水印_Python 3.x_Matplotlib - Fatal编程技术网

Python 3.x Python 3 matplotlib添加具有多个缩放轴的水印

Python 3.x Python 3 matplotlib添加具有多个缩放轴的水印,python-3.x,matplotlib,Python 3.x,Matplotlib,在Python3中,我尝试在下面的数据帧中添加具有多个缩放轴的水印 index,as_of_date,Total_10bn,close 0,2020-08-05,620.55975367473,332.11 1,2020-08-12,621.9414641848599,337.44 2,2020-08-19,628.88298116372,337.23 3,2020-08-26,627.26943375402,347.57 4,2020-09-02,630.01703674403,357.7 5

在Python3中,我尝试在下面的数据帧中添加具有多个缩放轴的水印

index,as_of_date,Total_10bn,close
0,2020-08-05,620.55975367473,332.11
1,2020-08-12,621.9414641848599,337.44
2,2020-08-19,628.88298116372,337.23
3,2020-08-26,627.26943375402,347.57
4,2020-09-02,630.01703674403,357.7
5,2020-09-09,630.70673674269,339.79
6,2020-09-16,637.50390815142,338.82
我可以让多重比例工作

df_soma_spy=pd.read_csv('df_soma_spy.csv')

print(df_soma_spy)

# create figure and axis objects with subplots()

fig,ax = plt.subplots()

plt.xticks(rotation=90)

ax.plot(df_soma_spy.as_of_date, df_soma_spy.Total_10bn, color="red") ## , marker="o"

# set x-axis label

ax.set_xlabel("Date", fontsize=12)

# set y-axis label

ax.set_ylabel("Fed SOMA ($10bn)",color="red",fontsize=14)

plt.grid(True, axis='both', which='both')

# twin object for two different y-axis on the sample plot

ax2=ax.twinx()

# make a plot with different y-axis using second axis object

ax2.plot(df_soma_spy.as_of_date, df_soma_spy["close"], color="black") ## , marker="o"

ax2.set_ylabel("$SPY Price",color="black",fontsize=14)


plt.title('Federal Reserves SOMA Total vs $SPY')

plt.show()

# save the plot as a file
fig.savefig('soma_spy.png',
            format='jpeg',
            dpi=300,
            bbox_inches='tight')

现在我正试图在图片后面添加一个徽标。但不管我怎么尝试,它都会弄乱一个轴心

比如说

import matplotlib.image as image

im = image.imread('xxx.png')

myaximage = ax.imshow(im, aspect='auto', extent=(0.1,0.1,0.1,0.1), alpha=0.5, zorder=-1)
在这种情况下,徽标没有显示,红色轴完全乱了

还有其他一些解决方案,但似乎都不起作用

有什么想法吗?谢谢大家!

可以使用fig.figimage()代替ax.imshow(),如下所示和所述。只需在代码中插入以下两行:

logo = image.imread(fname='logo.png')
fig.figimage(logo,alpha= 0.1)
使用您提供的部分数据,以下是保存的图像:


完美而简单的解决方案!我正试图把水线移到左上角。玩弄几个参数,但它们似乎都不起作用。有小费吗?非常感谢。哇,你是一名神经外科医生@pakpe!太有才华了!谢谢您可以使用figimage参数,但它们很麻烦,偏移量只显示在显示的图像上,而不显示在保存的图像上。可能获得精确结果的最佳方法是对图像进行预处理。例如,使用Photoshop将水印定位在画布上与保存的图形大小和分辨率相同的所需位置。这一点很好。谢谢你@pakpe