Huanian Zhang
Huanian Zhang

Reputation: 860

Python 3 matplotlit figure saved broken

I use the python 3 to make a figure, it displays very well, but when I save it, it is broken for the right half, as figures appended below. I am not sure what is wrong with it. The code I have is the following:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import rcParams, AutoMinorLocator

params = {'backend': 'ps',
      'font.size': 30,
      'font.style': 'normal',
      'axes.labelsize': 30,
      #'text.fontsize': 30,
      'axes.linewidth': 2,
      'legend.fontsize': 12,
      'xtick.labelsize': 30,
      'ytick.labelsize': 30,
      'xtick.top': True,
      'ytick.right': True,
      #'xtick.major.top': True,
      #'xtick.minor.top': True,
      #'ytick.major.right': True,
      #'ytick.minor.right': True,
      'text.usetex': True,
      'ps.usedistiller': 'xpdf'}

rcParams.update(params)


ion = [-2.0, -2.5, -3.0, -3.25, -3.5, -4.0, -4.5, -5.0, -5.5, -6.0]
cooling_mass = [0.036409, 0.035329, 0.042622, 0.069795, 0.090708, 0.107212, 0.109671, 0.110513, 0.107213, 0.109558]

fig, ax = plt.subplots(1, figsize=(8,6))
minor_locator1 = AutoMinorLocator(5)
ax.xaxis.set_minor_locator(minor_locator1)
minor_locator2 = AutoMinorLocator(5)
ax.yaxis.set_minor_locator(minor_locator2)
ax.tick_params('both', length=10, width=2, direction='in',which='major',pad=8)
ax.tick_params('both', length=5, width=2, direction='in',which='minor',pad=8)

ax.axhspan(0.036, 0.107, facecolor='lightskyblue', alpha=0.5)
ax.scatter(ion, cooling_mass, color='b', marker = 'o', s=50, zorder=2)

ax.set_ylim([0.008,0.14])
ax.set_yticks([0.03,0.06,0.09,0.12])
ax.set_xlim([-6.5,-1.5])
ax.set_xticks([-6.0,-4.0,-2.0])
ax.set_ylabel(r'$\rm Cooling ~Mass ~Rate ~[\rm M_\odot/yr]$', size=20, labelpad=5)
ax.set_xlabel(r'$\log {\rm U}$')

plt.gca().invert_xaxis()

plt.savefig('ion_cooling.eps',bbox_inches='tight')
plt.show()

enter image description here

Upvotes: 0

Views: 70

Answers (0)

Related Questions