【问题标题】:Savefig as eps yields a non-usable epsSavefig as eps 产生一个不可用的 eps
【发布时间】:2015-11-23 23:03:11
【问题描述】:

我尝试将 IPython 中的绘图保存为 eps,起初它似乎可以工作,但是一旦我尝试通过乳胶或 word 访问绘图,它就不会显示任何内容。如果我将绘图保存为 png 或 jpg,它可以正常工作。命令savefig() 和我尝试通过ipython 图保存绘图时都会出现问题。

编辑: 仅当我使用“import seaborn”时才会出现问题,纯matplotlib 实际上适用于 eps!

例子:

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
path = 'D:\\'

# Set up the matplotlib figure
f, (ax1, ax2) = plt.subplots(2, 1, figsize=(8, 6), sharex=True)

# Generate some sequential data
x = np.arange(60)
y1 = np.random.standard_normal(60)
f1 = sns.barplot(x, y1, palette="BuGn_d", ax=ax1)
ax1.set_ylabel("t-values")
ax1.set_xlabel("Lag $r_t$")
f1.text(35, 4, 'OLS: $\\frac{r_t}{\\sigma_{t-1}}= \\alpha +'
               '\\beta_{h} \\frac{r_{t-h}}{\\sigma_{t-h-1}} +'
               '\\epsilon_{t}$', fontsize=14)
y2 = np.random.standard_normal(60)
f2 = sns.barplot(x, y2, palette="RdBu_r", ax=ax2)
ax2.set_ylabel("t-values")
ax2.set_xlabel("Lag $r_t$")
f2.text(35, 4, 'OLS: $\\frac{r_t}{\\sigma_{t-1}}= \\alpha +'
               '\\beta_{h} sign(r_{t-h}) + \\epsilon_{t}$', fontsize=14)

sns.despine(bottom=True)
plt.setp(f.axes, yticks=[-3,-1,1,3,5])
plt.tight_layout(h_pad=3)
f.suptitle('t-values of lagged returns (Driscoll Kraay robust SE)')

f.savefig('\\'.join([path,'t_stats_robust.jpg']), format='jpg', dpi=1000,
          orientation='landscape')
f.savefig('\\'.join([path,'t_stats_robust.eps']), format='eps', dpi=1000,
          orientation='landscape')

【问题讨论】:

  • 请提供mwe
  • 你确定这不是在 LaTeX/Word 中嵌入图形的问题吗?可以在Photoshop/GIMP/Ghostscript等中打开图吗?
  • 我已经添加了显式问题作为示例。我无法在 GIMP 中打开图,它会引发错误(无法解释文件)
  • 我刚刚发现问题只发生在我使用import seaborn 绘制纯matplotlib 用作eps 时

标签: python matplotlib ipython seaborn


【解决方案1】:

该问题与matplotlib 中的问题有关。 ps 和 eps 问题与在win os-systems 上使用时的 rcParams 规范有关。请参阅github issue link 以获得快速修复和跟踪错误修复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2023-03-27
    • 2015-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多