简体   繁体   English

如何将纵横轴标签设置为粗体或字体

[英]How to set the vertical and horizontal axis labels to bold size or font

How do i get bold fonts for the x and y labels.如何获得 x 和 y 标签的粗体字体。 I used weight='bold' for plt but is not working for host.我将weight='bold'用于 plt 但不适用于主机。

from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA

if 2:
    host = host_subplot(111, axes_class=AA.Axes)
    plt.subplots_adjust(right=0.75)
    par1 = host.twinx()
    par2 = host.twinx()
    offset = 60
    new_fixed_axis = par2.get_grid_helper().new_fixed_axis
    par2.axis["right"] = new_fixed_axis(loc="right",
                                        axes=par2,
                                        offset=(offset, 0))
    par2.axis["right"].toggle(all=True)
    host.set_xlim(1, 9)
    host.set_ylim(200,1100)
    host.set_xlabel('Station Number [-]', weight='bold')
    host.set_ylabel('Temperature [K]', weight='bold')
    par1.set_ylabel('Pressure [kPa]', weight='bold')
    par2.set_ylabel("Mass flow rate [kg/s]", weight='bold')
    p1, = host.plot(Station, Total_temperature,'k-*',label="Total Temperature",ms=8,mew=2,mfc='w',linewidth=2)
    p1, = host.plot(Station, Static_temperature, 'k--o',label="Static Temperature",ms=8,mew=2,linewidth=2)
    p2, = par1.plot(Station, Total_pressure, 'k-v',label="Total Pressure",ms=8,mew=2,mfc='w',linewidth=2)
    p2, = par1.plot(Station, Static_pressure,'k--d',label="Static Pressure",ms=8,mew=2,linewidth=2)
    p3, = par2.plot(Station, Mass_flow,'k-x',label="Mass Flow Rate",ms=8,mew=2,mfc='w',linewidth=2)
    plt.grid()
    par1.set_ylim(40,400)
    par2.set_ylim(0.287,0.294)
    host.legend(prop={'size':12}, loc='center right')
    #legend1 = host.legend(('Total Temperature', 'Static Temperature', 'Mass Flow Rate'),'upper right', prop={'size':13})
    #plt.legend(('Total Pressure','Static Pressure'),'lower right',prop={'size':13})
    #plt.gca().add_artist(legend1)
    host.axis["left"].label.set_color(p1.get_color())
    par1.axis["right"].label.set_color(p2.get_color())
    par2.axis["right"].label.set_color(p3.get_color())
    plt.savefig('Stations.svg')
    plt.draw()
    plt.show()

To change the font properties of axes.set_xlabel / axes.set_ylabel , weight='bold' needs to be passed inside the fontdict keyword dictionary, not as a standalone keyword argument.要更改axes.set_xlabel / axes.set_ylabel的字体属性,需要在fontdict关键字字典中传递weight='bold' ,而不是作为独立的关键字参数。 For example:例如:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.set_xlabel('xlabel', fontdict=dict(weight='bold'))

plt.show()

在此处输入图片说明

You can use fontweight="Bold".您可以使用 fontweight="Bold"。 It should work fine.它应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM