Python matplotlib更改坐标刻度颜色
菜鸟向前冲fighting 人气:02D坐标系
1 修改全部坐标颜色
import matplotlib.pyplot as plt import numpy as np #显示静态图像 %matplotlib inline#jupyter notebok语句 x=np.linspace(-1,1,50)#-1到1中画50个点 y=x**2 plt.plot(x,y,) ###################以下两条语句用于更改颜色####################### plt.tick_params(axis='x',colors='red') plt.tick_params(axis='y',colors='red') plt.show()
2 修改某一点坐标颜色
import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(5,4)) ax.plot([1,2,3]) ###################更改某一点刻度颜色####################### ax.get_xticklabels()[3].set_color("red") # 这里的数字3是表示第几个点,不是坐标刻度值 ax.get_yticklabels()[5].set_color("red") plt.show()
3D坐标系
1 修改全部坐标颜色
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig=plt.figure(num=1,figsize=(8,6)) ax = Axes3D(fig) # X, Y value X = np.arange(-4, 4, 0.25) Y = np.arange(-4, 4, 0.25) X, Y = np.meshgrid(X, Y) R = np.sqrt(X ** 2 + Y ** 2) # height value Z = np.cos(R) ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow'),edgecolors='black') ax.contourf(X, Y, Z, zdir='z', offset=-2, cmap=plt.get_cmap('rainbow'))#投影等高线,改变zdir='x', offset=-4实现投影到不同坐标轴 ax.set_zlim(-2, 2) ###################以下三条语句用于更改颜色####################### ax.tick_params(axis='x',colors='red') ax.tick_params(axis='y',colors='red') ax.tick_params(axis='z',colors='red') plt.show()
2 修改某一点坐标颜色
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig=plt.figure(num=1,figsize=(8,6)) ax = Axes3D(fig) # X, Y value X = np.arange(-4, 4, 0.25) Y = np.arange(-4, 4, 0.25) X, Y = np.meshgrid(X, Y) R = np.sqrt(X ** 2 + Y ** 2) # height value Z = np.cos(R) ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow'),edgecolors='black') ax.contourf(X, Y, Z, zdir='z', offset=-2, cmap=plt.get_cmap('rainbow'))#投影等高线,改变zdir='x', offset=-4实现投影到不同坐标轴 ax.set_zlim(-2, 2) ###################以下三条语句用于更改颜色####################### ax.get_xticklabels()[3].set_color("red") ax.get_yticklabels()[5].set_color("red") ax.get_zticklabels()[7].set_color("red") plt.show()
总结
加载全部内容