Matplotlib乳胶组分中的垂直间距

时间:2017-07-05 00:14:29

标签: python matplotlib latex

我已经为我的x刻度标签创建了小数值,但这些分数看起来有点局促。有没有办法增加垂直间距?

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.set_xlim(0, 10)
ax.set_xticklabels(
    ['$\\frac{enter image description here}{<?php 
  $response = file_get_contents('https://sisa.msal.gov.ar/sisa/services/rest/puco/44003375');
  $response = new SimpleXMLElement($response);
  dd($response);
?>
}$'.format('M', x) for x in ax.get_xticks()],
    fontsize=12)

plt.show()

{{0}}

2 个答案:

答案 0 :(得分:1)

使用\dfrac可能会有所帮助。但是,我们需要修改序言。

import matplotlib.pyplot as plt
plt.rc('text', usetex=True)
plt.rc('text.latex', preamble=r'\usepackage{amsmath}')
fig, ax = plt.subplots()

ax.set_xlim(0, 10)
ax.set_xticklabels(
    ['$\\dfrac{enter image description here}{//same values
var deviceMessageList1 = _deviceMessageRepository.Fromdevicemessages
                .Where(m => m.DeviceId == deviceId).Take(1000).ToList();
//different values
            var deviceMessageList2 = _deviceMessageRepository.Fromdevicemessages
                .Where(m => m.DeviceId == deviceId).Take(1000).Select(x=> new { Message = x.Message }).ToList();
}$'.format('M', x) for x in ax.get_xticks()],
    fontsize=12)

Sample

此处提供更多信息:How to write your own LaTeX preamble in Matplotlib?

答案 1 :(得分:0)

可以通过强制Matplotlib使用LaTeX而不是mathtext来改善垂直间距:

plt.rcParams['text.usetex'] = True
plt.rcParams['text.latex.preamble'] = [r'\usepackage{sansmath}', r'\sansmath']

sansmath包保留sans-serif类型:

之前的

enter image description here之后:enter image description here