matplotlib画图时的格式设置(matplotlib3D绘图笔记字体)
matplotlib画图时的格式设置(matplotlib3D绘图笔记字体)
- 字体
rc('text' usetex=True)
plt.rc('font' family='Times New Roman' size=20)
- 边框
plt.rc('axes' edgecolor='white')
- 背景
## 背景rgb a参数
ax3d.w_xaxis.set_pane_color((1.0 1.0 1.0 1.0))
ax3d.w_yaxis.set_pane_color((1.0 1.0 1.0 1.0))
ax3d.w_zaxis.set_pane_color((1.0 1.0 1.0 1.0))
- 视角
ax3d.view_init(10 -60)
完整代码
import numpy as np
from numpy import *
import matplotlib as mpl
import os
from matplotlib import pyplot as plt
from matplotlib import rc
from matplotlib import cm
import sys
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.colors as colors
rc('text' usetex=True)
plt.rc('font' family='Times New Roman' size=20)
plt.rc('axes' edgecolor='white')
fig = plt.figure(figsize=(20 20))
ax3d = fig.add_subplot(projection='3d')
#画直角坐标系
x = np.linspace(-2 2 201)
y = np.zeros(201 dtype=float)
z = x*y*0
ax3d.quiver3D(-1 0 0 3 0 0 color='k'
linestyle='-' linewidth=1 arrow_length_ratio=.02)
ax3d.quiver3D(0 -1 0 0 3 0 color='k'
linestyle='-' linewidth=1 arrow_length_ratio=.02)
ax3d.quiver3D(0 0 -1 0 0 3 color='k'
linestyle='-' linewidth=1 arrow_length_ratio=.02)
### 加入text
ax3d.text(2.1 0 0 r'$x$')
ax3d.text(0 2.1 0 r'$y$')
ax3d.text(0 0 2.1 r'$z$')
x y z u v w = [0 0 0 1.0 1.0 1.5]
ax3d.quiver3D(x y z u v w color='gray'
linestyle='-.'
linewidth=3 arrow_length_ratio=0.1)
##设置坐标轴刻度
ax3d.set_xticks([])
ax3d.set_yticks([])
ax3d.set_zticks([])
ax3d.set_xlim(-2 2)
ax3d.set_ylim(-2 2)
ax3d.set_zlim(-2 2)
##视角
ax3d.view_init(10 -60)
## 背景rgb a参数
ax3d.w_xaxis.set_pane_color((1.0 1.0 1.0 1.0))
ax3d.w_yaxis.set_pane_color((1.0 1.0 1.0 1.0))
ax3d.w_zaxis.set_pane_color((1.0 1.0 1.0 1.0))
#plt.legend()
plt.savefig('test_quiver.pdf' transparent=True dpi=300)
效果
matplotlib绘图:没有边框白色背景的直角坐标系