matplotlib, 对之前所画图形的美化,matplotlib所画,1.之前在画”华氏温度到


1.之前在画”华氏温度到摄氏温度转换图“时,并没有太在意图形的美化,在expl0rer的提示下,现对原代码进行一定的修正。

2.附两张图:第一张未使用LaTex编辑公式,第二张使用了LaTex,但出现了乱码。

3.顺便请高人指点一下乱码的原因。

# -*- coding: utf-8 -*-import numpy as npimport matplotlib.pyplot as pltimport matplotlibF = np.arange(-50, 240, 0.1)C = (F - 32)/1.8fig, ax = plt.subplots()# Set axis spines at 0for spine in ['left', 'bottom']:    ax.spines[spine].set_position('zero')# Hide the other spines...for spine in ['right', 'top']:    ax.spines[spine].set_color('none')# X-axis arrowax.annotate('Fahrenheit', xy=(1, 0), xycoords=('axes fraction', 'data'),             xytext=(5, 0), textcoords='offset points',            ha='left', va='center', fontsize=7,            arrowprops=dict(arrowstyle='<|-', fc='black'))# Y-axis arrowax.annotate('Centigrade', xy=(0, 1), xycoords=('data', 'axes fraction'),             xytext=(0, 5), textcoords='offset points',            ha='center', va='bottom', fontsize=7,            arrowprops=dict(arrowstyle='<|-', fc='black'))# Basicplt.plot(F, C, 'r-', linewidth = 0.5, label=r'$\\frac{F-32}{1.8}$')plt.title('Convert the unit of temperature', va='bottom', ha='center', fontsize=10)plt.legend(fontsize=7, loc='best', frameon=False)# Ticksax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(20))ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(4))ax.yaxis.set_major_locator(matplotlib.ticker.MultipleLocator(20))ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(4))sc = np.array([-40, -20, 20, 37, 60, 80, 100])sf = np.array([-40, 32, 80, 37*1.8+32, 140, 180, 100*1.8+32])plt.yticks(sc); plt.xticks(sf)plt.grid(b = True)# Specific temperaturesplt.scatter([32, ], [0, ], 50, color = 'blue')plt.plot([0, 37*1.8+32], [37, 37], color = 'blue', linewidth = 1.5, linestyle = '--')plt.plot([37*1.8+32, 37*1.8+32], [0, 37], color = 'blue', linewidth = 1.5, linestyle = '--')plt.scatter([37*1.8+32, ], [37, ], 50, color = 'blue')plt.plot([0, 100*1.8+32], [100, 100], color = 'blue', linewidth = 1.5, linestyle = '--')plt.plot([100*1.8+32, 100*1.8+32], [0, 100], color = 'blue', linewidth = 1.5, linestyle = '--')plt.scatter([100*1.8+32, ], [100, ], 50, color = 'blue')plt.savefig('FtoC.pdf')plt.close()#该片段来自于http://byrx.net

评论关闭