Python matplotlib.font_manager.FontProperties() Examples

The following are 30 code examples of matplotlib.font_manager.FontProperties(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.font_manager , or try the search function .
Example #1
Source File: axis.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def _get_text2(self):

        'Get the default Text 2 instance'
        # x in data coords, y in axes coords
        #t =  mtext.Text(
        trans, vert, horiz = self._get_text2_transform()
        t = mtext.Text(
            x=0, y=1,
            fontproperties=font_manager.FontProperties(size=self._labelsize),
            color=self._labelcolor,
            verticalalignment=vert,
            horizontalalignment=horiz,
            )
        t.set_transform(trans)
        self._set_artist_props(t)
        return t 
Example #2
Source File: legend.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def set_title(self, title, prop=None):
        """
        set the legend title. Fontproperties can be optionally set
        with *prop* parameter.
        """
        self._legend_title_box._text.set_text(title)

        if prop is not None:
            if isinstance(prop, dict):
                prop = FontProperties(**prop)
            self._legend_title_box._text.set_fontproperties(prop)

        if title:
            self._legend_title_box.set_visible(True)
        else:
            self._legend_title_box.set_visible(False) 
Example #3
Source File: legend.py    From Computable with MIT License 6 votes vote down vote up
def set_title(self, title, prop=None):
        """
        set the legend title. Fontproperties can be optionally set
        with *prop* parameter.
        """
        self._legend_title_box._text.set_text(title)

        if prop is not None:
            if isinstance(prop, dict):
                prop = FontProperties(**prop)
            self._legend_title_box._text.set_fontproperties(prop)

        if title:
            self._legend_title_box.set_visible(True)
        else:
            self._legend_title_box.set_visible(False) 
Example #4
Source File: axis.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def _get_label(self):
        # x in display coords (updated by _update_label_position)
        # y in axes coords
        label = mtext.Text(x=0, y=0.5,
            # todo: get the label position
            fontproperties=font_manager.FontProperties(
                               size=rcParams['axes.labelsize'],
                               weight=rcParams['axes.labelweight']),
            color=rcParams['axes.labelcolor'],
            verticalalignment='bottom',
            horizontalalignment='center',
            rotation='vertical',
            rotation_mode='anchor',
            )
        label.set_transform(mtransforms.blended_transform_factory(
            mtransforms.IdentityTransform(), self.axes.transAxes))

        self._set_artist_props(label)
        self.label_position = 'left'
        return label 
Example #5
Source File: axis.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def _get_label(self):
        # x in axes coords, y in display coords (to be updated at draw
        # time by _update_label_positions)
        label = mtext.Text(x=0.5, y=0,
            fontproperties=font_manager.FontProperties(
                               size=rcParams['axes.labelsize'],
                               weight=rcParams['axes.labelweight']),
            color=rcParams['axes.labelcolor'],
            verticalalignment='top',
            horizontalalignment='center',
            )

        label.set_transform(mtransforms.blended_transform_factory(
            self.axes.transAxes, mtransforms.IdentityTransform()))

        self._set_artist_props(label)
        self.label_position = 'bottom'
        return label 
Example #6
Source File: mathtext.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def get_depth(self, texstr, dpi=120, fontsize=14):
        """
        Returns the offset of the baseline from the bottom of the
        image in pixels.

        *texstr*
            A valid mathtext string, eg r'IQ: $\sigma_i=15$'

        *dpi*
            The dots-per-inch to render the text

        *fontsize*
            The font size in points
        """
        assert(self._output=="bitmap")
        prop = FontProperties(size=fontsize)
        ftimage, depth = self.parse(texstr, dpi=dpi, prop=prop)
        return depth 
Example #7
Source File: mathtext.py    From Computable with MIT License 6 votes vote down vote up
def get_depth(self, texstr, dpi=120, fontsize=14):
        """
        Returns the offset of the baseline from the bottom of the
        image in pixels.

        *texstr*
            A valid mathtext string, eg r'IQ: $\sigma_i=15$'

        *dpi*
            The dots-per-inch to render the text

        *fontsize*
            The font size in points
        """
        assert(self._output=="bitmap")
        prop = FontProperties(size=fontsize)
        ftimage, depth = self.parse(texstr, dpi=dpi, prop=prop)
        return depth 
Example #8
Source File: axis.py    From Computable with MIT License 6 votes vote down vote up
def _get_text2(self):

        'Get the default Text 2 instance'
        # x in data coords, y in axes coords
        #t =  mtext.Text(
        trans, vert, horiz = self._get_text2_transform()
        t = mtext.Text(
            x=0, y=1,
            fontproperties=font_manager.FontProperties(size=self._labelsize),
            color=self._labelcolor,
            verticalalignment=vert,
            horizontalalignment=horiz,
            )
        t.set_transform(trans)
        self._set_artist_props(t)
        return t 
Example #9
Source File: axis.py    From Computable with MIT License 6 votes vote down vote up
def _get_text1(self):
        'Get the default Text instance'
        # the y loc is 3 points below the min of y axis
        # get the affine as an a,b,c,d,tx,ty list
        # x in data coords, y in axes coords
        #t =  mtext.Text(
        trans, vert, horiz = self._get_text1_transform()
        t = mtext.Text(
            x=0, y=0,
            fontproperties=font_manager.FontProperties(size=self._labelsize),
            color=self._labelcolor,
            verticalalignment=vert,
            horizontalalignment=horiz,
            )
        t.set_transform(trans)
        self._set_artist_props(t)
        return t 
Example #10
Source File: axis.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def _get_text1(self):
        'Get the default Text instance'
        # the y loc is 3 points below the min of y axis
        # get the affine as an a,b,c,d,tx,ty list
        # x in data coords, y in axes coords
        #t =  mtext.Text(
        trans, vert, horiz = self._get_text1_transform()
        t = mtext.Text(
            x=0, y=0,
            fontproperties=font_manager.FontProperties(size=self._labelsize),
            color=self._labelcolor,
            verticalalignment=vert,
            horizontalalignment=horiz,
            )
        t.set_transform(trans)
        self._set_artist_props(t)
        return t 
Example #11
Source File: legend.py    From Mastering-Elasticsearch-7.0 with MIT License 6 votes vote down vote up
def set_title(self, title, prop=None):
        """
        Set the legend title. Fontproperties can be optionally set
        with *prop* parameter.
        """
        self._legend_title_box._text.set_text(title)
        if title:
            self._legend_title_box._text.set_visible(True)
            self._legend_title_box.set_visible(True)
        else:
            self._legend_title_box._text.set_visible(False)
            self._legend_title_box.set_visible(False)

        if prop is not None:
            if isinstance(prop, dict):
                prop = FontProperties(**prop)
            self._legend_title_box._text.set_fontproperties(prop)

        self.stale = True 
Example #12
Source File: axis.py    From Mastering-Elasticsearch-7.0 with MIT License 6 votes vote down vote up
def _get_label(self):
        # x in display coords (updated by _update_label_position)
        # y in axes coords
        label = mtext.Text(x=0, y=0.5,
                           # todo: get the label position
                           fontproperties=font_manager.FontProperties(
                               size=rcParams['axes.labelsize'],
                               weight=rcParams['axes.labelweight']),
                           color=rcParams['axes.labelcolor'],
                           verticalalignment='bottom',
                           horizontalalignment='center',
                           rotation='vertical',
                           rotation_mode='anchor')
        label.set_transform(mtransforms.blended_transform_factory(
            mtransforms.IdentityTransform(), self.axes.transAxes))

        self._set_artist_props(label)
        self.label_position = 'left'
        return label 
Example #13
Source File: axis.py    From Mastering-Elasticsearch-7.0 with MIT License 6 votes vote down vote up
def _get_label(self):
        # x in axes coords, y in display coords (to be updated at draw
        # time by _update_label_positions)
        label = mtext.Text(x=0.5, y=0,
                           fontproperties=font_manager.FontProperties(
                               size=rcParams['axes.labelsize'],
                               weight=rcParams['axes.labelweight']),
                           color=rcParams['axes.labelcolor'],
                           verticalalignment='top',
                           horizontalalignment='center')

        label.set_transform(mtransforms.blended_transform_factory(
            self.axes.transAxes, mtransforms.IdentityTransform()))

        self._set_artist_props(label)
        self.label_position = 'bottom'
        return label 
Example #14
Source File: axis.py    From Mastering-Elasticsearch-7.0 with MIT License 6 votes vote down vote up
def _get_text1(self):
        'Get the default Text instance'
        # the y loc is 3 points below the min of y axis
        # get the affine as an a,b,c,d,tx,ty list
        # x in data coords, y in axes coords
        trans, vert, horiz = self._get_text1_transform()
        t = mtext.Text(
            x=0, y=0,
            fontproperties=font_manager.FontProperties(size=self._labelsize),
            color=self._labelcolor,
            verticalalignment=vert,
            horizontalalignment=horiz,
            )
        t.set_transform(trans)
        self._set_artist_props(t)
        return t 
Example #15
Source File: parse_svg.py    From pylustrator with GNU General Public License v3.0 6 votes vote down vote up
def font_properties_from_style(style: dict) -> FontProperties:
    """ convert a style to a FontProperties object """
    fp = FontProperties()
    for key, value in style.items():
        if key == "font-family":
            fp.set_family(value)
        if key == "font-size":
            fp.set_size(svgUnitToMpl(value))
        if key == "font-weight":
            fp.set_weight(value)
        if key == "font-style":
            fp.set_style(value)
        if key == "font-variant":
            fp.set_variant(value)
        if key == "font-stretch":
            fp.set_stretch(value)
    return fp 
Example #16
Source File: plot_tools.py    From ctw-baseline with MIT License 6 votes vote down vote up
def draw_bar(data, labels, width=None, xticks_font_fname=None, legend_kwargs=dict()):
    n = len(labels)
    m = len(data)
    if not width:
        width = 1. / (m + .6)
    off = 1.
    legend_bar = []
    legend_text = []
    for i, a in enumerate(data):
        for j, b in enumerate(a):
            assert n == len(b['data'])
            ind = [off + k + (i + (1 - m) / 2) * width for k in range(n)]
            bottom = [sum(d) for d in zip(*[c['data'] for c in a[j + 1:]])] or None
            p = plt.bar(ind, b['data'], width, bottom=bottom, color=b.get('color'))
            legend_bar.append(p[0])
            legend_text.append(b['legend'])
    ind = [off + i for i, label in enumerate(labels) if label is not None]
    labels = [label for label in labels if label is not None]
    font = FontProperties(fname=xticks_font_fname)
    plt.xticks(ind, labels, fontproperties=font, ha='center')
    plt.legend(legend_bar, legend_text, **legend_kwargs) 
Example #17
Source File: axis.py    From neural-network-animation with MIT License 6 votes vote down vote up
def _get_text1(self):
        'Get the default Text instance'
        # the y loc is 3 points below the min of y axis
        # get the affine as an a,b,c,d,tx,ty list
        # x in data coords, y in axes coords
        #t =  mtext.Text(
        trans, vert, horiz = self._get_text1_transform()
        t = mtext.Text(
            x=0, y=0,
            fontproperties=font_manager.FontProperties(size=self._labelsize),
            color=self._labelcolor,
            verticalalignment=vert,
            horizontalalignment=horiz,
            )
        t.set_transform(trans)
        self._set_artist_props(t)
        return t 
Example #18
Source File: summary.py    From neleval with Apache License 2.0 5 votes vote down vote up
def make_small_font():
    from matplotlib.font_manager import FontProperties
    font = FontProperties()
    font.set_size('small')
    return font 
Example #19
Source File: helper_functions.py    From pylustrator with GNU General Public License v3.0 5 votes vote down vote up
def get_letter_font_prop():
    """ get the properties of the subplot letters to add """
    from matplotlib.font_manager import FontProperties
    font = FontProperties()
    font.set_family("C:\\WINDOWS\\Fonts\\HelveticaNeue-CondensedBold.ttf")
    font.set_weight("heavy")
    font.set_size(10)
    font.letter_format = "a"
    return font 
Example #20
Source File: regression.py    From AILearners with Apache License 2.0 5 votes vote down vote up
def plotlwlrRegression():
    font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
    xArr, yArr = loadDataSet('C:/Users/Administrator/Desktop/blog/github/AILearners/data/ml/jqxxsz/8.Regression/ex0.txt')                                    #加载数据集
    yHat_1 = lwlrTest(xArr, xArr, yArr, 1.0)                            #根据局部加权线性回归计算yHat
    yHat_2 = lwlrTest(xArr, xArr, yArr, 0.01)                            #根据局部加权线性回归计算yHat
    yHat_3 = lwlrTest(xArr, xArr, yArr, 0.003)                            #根据局部加权线性回归计算yHat
    xMat = np.mat(xArr)                                                    #创建xMat矩阵
    yMat = np.mat(yArr)                                                    #创建yMat矩阵
    srtInd = xMat[:, 1].argsort(0)                                        #排序,返回索引值
    xSort = xMat[srtInd][:,0,:]
    fig, axs = plt.subplots(nrows=3, ncols=1,sharex=False, sharey=False, figsize=(10,8))                                        
    axs[0].plot(xSort[:, 1], yHat_1[srtInd], c = 'red')                        #绘制回归曲线
    axs[1].plot(xSort[:, 1], yHat_2[srtInd], c = 'red')                        #绘制回归曲线
    axs[2].plot(xSort[:, 1], yHat_3[srtInd], c = 'red')                        #绘制回归曲线
    axs[0].scatter(xMat[:,1].flatten().A[0], yMat.flatten().A[0], s = 20, c = 'blue', alpha = .5)                #绘制样本点
    axs[1].scatter(xMat[:,1].flatten().A[0], yMat.flatten().A[0], s = 20, c = 'blue', alpha = .5)                #绘制样本点
    axs[2].scatter(xMat[:,1].flatten().A[0], yMat.flatten().A[0], s = 20, c = 'blue', alpha = .5)                #绘制样本点
    #设置标题,x轴label,y轴label
    axs0_title_text = axs[0].set_title(u'局部加权回归曲线,k=1.0',FontProperties=font)
    axs1_title_text = axs[1].set_title(u'局部加权回归曲线,k=0.01',FontProperties=font)
    axs2_title_text = axs[2].set_title(u'局部加权回归曲线,k=0.003',FontProperties=font)
    plt.setp(axs0_title_text, size=8, weight='bold', color='red')  
    plt.setp(axs1_title_text, size=8, weight='bold', color='red')  
    plt.setp(axs2_title_text, size=8, weight='bold', color='red')  
    plt.xlabel('X')
    plt.show() 
Example #21
Source File: axis_artist.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _draw_label2(self, renderer):

        if not self.label.get_visible():
            return

        fontprops = font_manager.FontProperties(
            size=rcParams['axes.labelsize'],
            weight=rcParams['axes.labelweight'])

        #pad_points = self.major_tick_pad

        #print self._ticklabel_add_angle - self._axislabel_add_angle
        #if abs(self._ticklabel_add_angle - self._axislabel_add_angle)%360 > 90:
        if self._ticklabel_add_angle !=  self._axislabel_add_angle:
            if (self.major_ticks.get_visible() and not self.major_ticks.get_tick_out()) \
               or \
               (self.minor_ticks.get_visible() and not self.major_ticks.get_tick_out()):
                axislabel_pad = self.major_ticks._ticksize
            else:
                axislabel_pad = 0
        else:
            axislabel_pad = max([self.major_ticklabels._axislabel_pad,
                                 self.minor_ticklabels._axislabel_pad])


        #label_offset =  axislabel_pad + self.LABELPAD

        #self.label._set_offset_radius(label_offset)
        self.label._set_external_pad(axislabel_pad)

        xy, angle_tangent = self._axis_artist_helper.get_axislabel_pos_angle(self.axes)
        if xy is None: return

        angle_label = angle_tangent  - 90


        x, y = xy
        self.label._set_ref_angle(angle_label+self._axislabel_add_angle)
        self.label.set(x=x, y=y)
        self.label.draw(renderer) 
Example #22
Source File: axis_artist.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _update_label(self, renderer):

        if not self.label.get_visible():
            return

        fontprops = font_manager.FontProperties(
            size=rcParams['axes.labelsize'],
            weight=rcParams['axes.labelweight'])

        #pad_points = self.major_tick_pad

        #print self._ticklabel_add_angle - self._axislabel_add_angle
        #if abs(self._ticklabel_add_angle - self._axislabel_add_angle)%360 > 90:
        if self._ticklabel_add_angle !=  self._axislabel_add_angle:
            if (self.major_ticks.get_visible() and not self.major_ticks.get_tick_out()) \
               or \
               (self.minor_ticks.get_visible() and not self.major_ticks.get_tick_out()):
                axislabel_pad = self.major_ticks._ticksize
            else:
                axislabel_pad = 0
        else:
            axislabel_pad = max([self.major_ticklabels._axislabel_pad,
                                 self.minor_ticklabels._axislabel_pad])


        #label_offset =  axislabel_pad + self.LABELPAD

        #self.label._set_offset_radius(label_offset)
        self.label._set_external_pad(axislabel_pad)

        xy, angle_tangent = self._axis_artist_helper.get_axislabel_pos_angle(self.axes)
        if xy is None: return

        angle_label = angle_tangent  - 90


        x, y = xy
        self.label._set_ref_angle(angle_label+self._axislabel_add_angle)
        self.label.set(x=x, y=y) 
Example #23
Source File: axis.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def _get_text2(self):
        'Get the default Text instance'
        # x in axes coords, y in data coords
        trans, vert, horiz = self._get_text2_transform()
        t = mtext.Text(
            x=1, y=0,
            fontproperties=font_manager.FontProperties(size=self._labelsize),
            color=self._labelcolor,
            verticalalignment=vert,
            horizontalalignment=horiz,
            )
        t.set_transform(trans)
        self._set_artist_props(t)
        return t 
Example #24
Source File: regression02.py    From AILearners with Apache License 2.0 5 votes vote down vote up
def plotwMat():
    font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
    abX, abY = loadDataSet('C:/Users/Administrator/Desktop/blog/github/AILearners/data/ml/jqxxsz/8.Regression/abalone.txt')
    redgeWeights = ridgeTest(abX, abY)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(redgeWeights)    
    ax_title_text = ax.set_title(u'log(lambada)与回归系数的关系', FontProperties = font)
    ax_xlabel_text = ax.set_xlabel(u'log(lambada)', FontProperties = font)
    ax_ylabel_text = ax.set_ylabel(u'回归系数', FontProperties = font)
    plt.setp(ax_title_text, size = 20, weight = 'bold', color = 'red')
    plt.setp(ax_xlabel_text, size = 10, weight = 'bold', color = 'black')
    plt.setp(ax_ylabel_text, size = 10, weight = 'bold', color = 'black')
    plt.show() 
Example #25
Source File: axis.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _get_offset_text(self):
        # x in display coords, y in axes coords (to be updated at draw time)
        offsetText = mtext.Text(x=0, y=0.5,
            fontproperties=font_manager.FontProperties(
                                          size=rcParams['ytick.labelsize']),
            color=rcParams['ytick.color'],
            verticalalignment='baseline',
            horizontalalignment='left',
            )
        offsetText.set_transform(mtransforms.blended_transform_factory(
                self.axes.transAxes, mtransforms.IdentityTransform()))
        self._set_artist_props(offsetText)
        self.offset_text_position = 'left'
        return offsetText 
Example #26
Source File: axis.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _get_text2(self):
        'Get the default Text instance'
        # x in axes coords, y in data coords
        trans, vert, horiz = self._get_text2_transform()
        t = mtext.Text(
            x=1, y=0,
            fontproperties=font_manager.FontProperties(size=self._labelsize),
            color=self._labelcolor,
            verticalalignment=vert,
            horizontalalignment=horiz,
            )
        t.set_transform(trans)
        self._set_artist_props(t)
        return t 
Example #27
Source File: axis.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _get_text1(self):
        'Get the default Text instance'
        # x in axes coords, y in data coords
        trans, vert, horiz = self._get_text1_transform()
        t = mtext.Text(
            x=0, y=0,
            fontproperties=font_manager.FontProperties(size=self._labelsize),
            color=self._labelcolor,
            verticalalignment=vert,
            horizontalalignment=horiz,
            )
        t.set_transform(trans)
        #t.set_transform( self.axes.transData )
        self._set_artist_props(t)
        return t 
Example #28
Source File: offsetbox.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def set_fontsize(self, s=None):
        """
        set fontsize in points
        """
        if s is None:
            s = rcParams["legend.fontsize"]

        self.prop = FontProperties(size=s)
        self.stale = True 
Example #29
Source File: axis.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def _get_offset_text(self):
        # x in display coords, y in axes coords (to be updated at draw time)
        offsetText = mtext.Text(x=0, y=0.5,
                                fontproperties=font_manager.FontProperties(
                                    size=rcParams['ytick.labelsize']
                                ),
                                color=rcParams['ytick.color'],
                                verticalalignment='baseline',
                                horizontalalignment='left')
        offsetText.set_transform(mtransforms.blended_transform_factory(
            self.axes.transAxes, mtransforms.IdentityTransform())
        )
        self._set_artist_props(offsetText)
        self.offset_text_position = 'left'
        return offsetText 
Example #30
Source File: axis.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def _get_text1(self):
        'Get the default Text instance'
        # x in axes coords, y in data coords
        trans, vert, horiz = self._get_text1_transform()
        t = mtext.Text(
            x=0, y=0,
            fontproperties=font_manager.FontProperties(size=self._labelsize),
            color=self._labelcolor,
            verticalalignment=vert,
            horizontalalignment=horiz,
            )
        t.set_transform(trans)
        self._set_artist_props(t)
        return t