簡體   English   中英

Matplotlib-更改用作繪圖背景的圖像的不透明度

[英]Matplotlib - changing opacity of the image used as a background for a plot

我已經使用matplotlib為繪圖設置圖像背景。 但是曲線的顏色在某些地方與背景混合在一起。 任何人都可以幫助我減少背景的不透明度,從而使實際圖更清晰可見。 到目前為止,我的代碼是-

import pandas as pd
import sys, os
import matplotlib.pyplot as plt
import numpy as np
import itertools
from scipy.misc import imread

def flip(items, ncol):
    return itertools.chain(*[items[i::ncol] for i in range(ncol)])

df = pd.read_pickle('neer.pickle')
rows = list(df.index)
countries = ['USA','CHN','JPN','DEU','GBR','FRA','IND','ITA','BRA','CAN','RUS']
x = range(len(rows))
df = df.pct_change()

fig, ax = plt.subplots(1)
for country in countries:
    ax.plot(x, df[country], label=country)

plt.xticks(x, rows, size='small', rotation=75)
#legend = ax.legend(loc='upper left', shadow=True)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.show(1)

df1 = df[countries]
plt.figure(2)
for country in countries:
    my_plot = plt.plot(x, 10*df[country], label=country)
img = imread("world.png")
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.imshow(img,zorder=0,  extent=[0.1, 30.0, -10.0, 10.0])
plt.set_alpha(0.5)
plt.title('Variation of NEER across the world')
plt.show(2)

在此處輸入圖片說明

您是否嘗試過類似的方法:

plt.imshow(img, zorder=0,  extent=[0.1, 30.0, -10.0, 10.0], alpha = 0.6)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM