我对Matplotlib很新,我一直在浏览他们非常好的网页,并设法生成与我想要的非常相似的东西。我将代码包含在我想要的情节中,我唯一能解决的问题是以粗体显示xlabel,ylabel和legend。 任何建议都会非常受欢迎, 非常感谢
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import numpy as np
from matplotlib.font_manager import FontProperties
from pylab import *
font = FontProperties()
font = {'family' : 'serif',
'weight' : 'bold',
'size' : 12,
}
fig = plt.figure(figsize=(6, 8))
matplotlib.rc('font', **font)
ax = host_subplot(211, axes_class=AA.Axes)
X=[0.061, 0.12, 0.17, 0.23, 0.29, 0.34, 0.4, 0.46, 0.51]
Y=[3.2, 4, 5.6, 7.4, 11.2, 18.6, 28.9, 42.5, 55.9]
Z=[3.2, 4.1, 5.7, 7.6, 11.3, 18.5, 27, 35.6, 46.9]
A=[3.2, 4, 5.6, 7.6, 11.3, 19.2, 30.4, 44.6, 57.7]
B=[3.2, 3.5, 4.8, 6.5, 10.4, 19.7, 32.9, 53.8, 84.2]
C=[3.1, 3.8, 5.6, 8, 13, 26.1, 41.1, 64.3, 103.7]
ax.plot(X, Y, color="red", linewidth=2.5, marker="v", markersize=7)
ax.plot(X, Z, color="orange", linewidth=2.5, marker="p", markersize=7)
ax.plot(X, A, color="yellow", linewidth=2.5, marker="s", markersize=7)
ax.plot(X, B, color="#33CC33", linewidth=2.5, marker="h", markersize=7)
ax.plot(X, C, color="green", linewidth=2.5, marker="D", markersize=7)
ax2 = ax.twin() # ax2 is responsible for "top" axis and "right" axis
ax2.set_xticks([0.061, 0.12, 0.17, 0.23, 0.29, 0.34, 0.4, 0.46, 0.51])
ax2.set_xticklabels(["4", "3","2.4", "2", "1.9", "1.7", "1.6", "1.5", "1.4$\AA$"])
ax2.axis["right"].major_ticklabels.set_visible(False)
ax.set_xlim(0.05, 0.52)
ax.set_ylim(0, 109)
plt.xlabel('1/d$^2$', fontsize=14, fontweight='bold')
plt.ylabel('R$_{meas}$')
plt.legend(("0.05deg/0.05s", "SUM20", "SUM40", "SUM80", "SUM160"))
fontsize=12, fancybox=True, shadow=True)
ax = host_subplot(212, axes_class=AA.Axes)
X=[0.061, 0.12, 0.17, 0.23, 0.29, 0.34, 0.4, 0.46, 0.51]
Y=[65, 62, 46, 35, 23, 13, 8, 4, 2]
Z=[65, 62, 47, 35, 23, 14, 9, 5, 3]
A=[66, 62, 47, 35, 23, 13, 8, 4, 2]
B=[71, 66, 48, 36, 23, 13, 8, 4, 2]
C=[70, 65, 48, 36, 23, 13, 8, 4, 2]
ax.plot(X, Y, color="red", linewidth=2.5, marker="v", markersize=7)
ax.plot(X, Z, color="orange", linewidth=2.5, marker="p", markersize=7)
ax.plot(X, A, color="yellow", linewidth=2.5, marker="s", markersize=7)
ax.plot(X, B, color="#33CC33", linewidth=2.5, marker="h", markersize=7)
ax.plot(X, C, color="green", linewidth=2.5, marker="D", markersize=7)
ax2 = ax.twin() # ax2 is responsible for "top" axis and "right" axis
ax2.set_xticks([0.061, 0.12, 0.17, 0.23, 0.29, 0.34, 0.4, 0.46, 0.51])
ax2.set_xticklabels(["4", "3","2.4", "2", "1.9", "1.7", "1.6", "1.5", "1.4$\AA$"])
ax2.axis["right"].major_ticklabels.set_visible(False)
ax.set_xlim(0.05, 0.52)
fig.subplots_adjust(hspace=0.3)
plt.xlabel('1/d$^2$', fontweight='bold')
plt.ylabel('I/sigma', fontdict=font)
plt.legend(("0.05deg/0.05s", "SUM20", "SUM40", "SUM80", "SUM160"))
plt.show()
答案 0 :(得分:0)
文本对象具有权重属性:http://matplotlib.org/users/text_props.html
plt.xlabel('This is my label', weight='bold')
plt.title('This is my title', weight='bold')