楼主: casey_c
4056 1

[程序分享] Matplotlib 库坐标轴刻度的设置与调整 [推广有奖]

  • 0关注
  • 10粉丝

博士生

92%

还不是VIP/贵宾

-

威望
0
论坛币
96 个
通用积分
2.1003
学术水平
2 点
热心指数
15 点
信用等级
2 点
经验
11502 点
帖子
278
精华
0
在线时间
94 小时
注册时间
2016-11-22
最后登录
2022-5-2

楼主
casey_c 发表于 2017-5-16 10:41:02 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
以下内容转自 数析学院,只节选了部分,有需要的同学可以直接查看原文

首先,我们需要在 Python 中导入所需的库与模块,并对 notebook 环境与图表风格进行初步的设置:


  1. %matplotlib inline
  2. import matplotlib.pyplot as plt
  3. plt.style.use('seaborn-whitegrid')
  4. import numpy as np
复制代码


运用 axes 函数,我们构建了一个空的坐标系,并将坐标轴刻度设置为幂形式:


  1. ax = plt.axes(xscale='log', yscale='log')
复制代码


1.jpg

Matplotlib 中的 ticker 模块用于支持坐标轴刻度的修改,调用下列命令可以初步查看主副坐标轴刻度的数值定位方式(locator)与具体格式(formatter):


  1. print(ax.xaxis.get_major_locator())
  2. print(ax.xaxis.get_minor_locator())
复制代码
<matplotlib.ticker.LogLocator object at 0x107530cc0><matplotlib.ticker.LogLocator object at 0x107530198>
  1. print(ax.xaxis.get_major_formatter())
  2. print(ax.xaxis.get_minor_formatter())
复制代码
<matplotlib.ticker.LogFormatterMathtext object at 0x107512780><matplotlib.ticker.NullFormatter object at 0x10752dc18>
我们可以使用 set_major_locatorset_major_formatter 命令来调整坐标轴的刻度,如去除坐标轴的刻度显示:
  1. ax = plt.axes()
  2. ax.plot(np.random.rand(50))

  3. ax.yaxis.set_major_locator(plt.NullLocator())
  4. ax.xaxis.set_major_formatter(plt.NullFormatter())
复制代码
2.jpg
以上内容转自 数析学院,只节选了部分,有需要的同学可以直接查看原文
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Matplotlib matplot plot TLI lib 坐标轴

沙发
casey_c 发表于 2017-5-19 11:28:13

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-3 14:33