garrettj403 / SciencePlots

Matplotlib styles for scientific plotting
MIT License
6.96k stars 700 forks source link

the problem of saving a figureof ieee style #73

Closed deemo-zheng closed 1 year ago

deemo-zheng commented 1 year ago

Hello! Thanks for your contirbutions. I have a problem about saving the picture when I drawing a picture of ieee style.

When I use the code following, it can‘t save the figure.

with plt.style.context(['science', 'ieee']):
    fig, ax = plt.subplots()
    ax.plot(axis_x, y_ads[i, :], label='EDA')
    ax.plot(axis_x, y_ztcnn[i, :], label='S-TCNN')
    ax.plot(axis_x, y_cnn[i, :], label='CNN')
    ax.set_xlabel('Frequency (Hz)')
    ax.set_ylabel(r'Impedance ($\Omega$)')
    ax.set_xscale('log')
    ax.set_yscale('log')
    ax.legend()
    plt.ylim(5e-5, 4)
    plt.savefig("./paper_need/No." + str(i) + '.svg', dpi=600, bbox_inches='tight')

It would have a error : "FileNotFoundError: missing font metrics file: rsfs10"

But when I use the code following, it can save.

with plt.style.context(['science', 'ieee']):
    fig, ax = plt.subplots()
    ax.plot(axis_x, y_ads[i, :], label='EDA')
    ax.plot(axis_x, y_ztcnn[i, :], label='S-TCNN')
    ax.plot(axis_x, y_cnn[i, :], label='CNN')
    ax.set_xlabel('Frequency (Hz)')
    ax.set_ylabel(r'Impedance ($\Omega$)')
    ax.set_xscale('log')
    ax.set_yscale('log')
    ax.legend()
    plt.ylim(5e-5, 4)
plt.savefig("./paper_need/No." + str(i) + '.svg', dpi=600, bbox_inches='tight')

It seems like that the code "plt.savefig()" can't bellow the code "with plt.style.context()".

garrettj403 commented 1 year ago

This is an issue with your Latex installation -- not with the SciencePlots package.

See: https://stackoverflow.com/questions/50875637/matplotlib-how-do-i-have-to-provide-font-metrics-files-for-rendering-text-by-te

deemo-zheng commented 1 year ago

Thanks! I have solved this issue.