在matplotlib中的乳胶中标记刻度线 [英] Mark ticks in latex in matplotlib

查看:101
本文介绍了在matplotlib中的乳胶中标记刻度线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在matplotlib中的绘图中,我特别想在x轴上将点标记为pi/2,pi,3pi/2,等等在乳胶中.我该怎么办?

In a plot in matplotlib I specially want to mark points on the x-axis as pi/2, pi, 3pi/2 and so on in latex. How can I do it?

推荐答案

plt.xticks命令可用于放置LaTeX刻度线.有关更多详细信息,请参见文档页面.

The plt.xticks command can be used to place LaTeX tick marks. See this doc page for more details.

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

cos = np.cos
pi = np.pi

# This is not necessary if `text.usetex : True` is already set in `matplotlibrc`.    
mpl.rc('text', usetex = True)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
t = np.linspace(0.0, 2*pi, 100)
s = cos(t)
plt.plot(t, s)

plt.xticks([0, pi/2, pi, 3*pi/2, 2*pi],
           ['$0$', r'$\frac{\pi}{2}$', r'$\pi$', r'$\frac{3\pi}{2}$', r'$2\pi$'])
plt.show()

这篇关于在matplotlib中的乳胶中标记刻度线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆