三、数据可视化:matplotlib.pyplot (mp) 14.半对数坐标 (只对y轴进行对数设置)

14.半对数坐标 (只对y轴进行对数设置)
mp.semilogy(…)

import numpy as np
import matplotlib.pyplot as mp
y = np.array([1, 10, 100, 1000, 100, 10, 1])
mp.figure('Normal & Log',
          facecolor='lightgray')
mp.subplot(211)
mp.title('Normal', fontsize=16)
mp.ylabel('y', fontsize=12)
ax = mp.gca()
# 坐标刻度定位器
ax.xaxis.set_major_locator(
    mp.MultipleLocator(1))
ax.xaxis.set_minor_locator(
    mp.MultipleLocator(0.1))
ax.yaxis.set_major_locator(
    mp.MultipleLocator(250))
ax.yaxis.set_minor_locator(
    mp.MultipleLocator(50))
mp.tick_params(labelsize=10)
mp.grid(which='major', axis='both',
        linewidth=0.75, linestyle='-',
        color='lightgray')
mp.grid(which='minor', axis='both',
        linewidth=0.25, linestyle='-',
        color='lightgray')

mp.plot(y, 'o-', c='dodgerblue', label='plot')  # x为索引,所以只画y
mp.legend()
mp.subplot(212)
mp.title('Log', fontsize=16)
mp.xlabel('x', fontsize=12)
mp.ylabel('y', fontsize=12)
ax = mp.gca()
ax.xaxis.set_major_locator(
    mp.MultipleLocator(1))
ax.xaxis.set_minor_locator(
    mp.MultipleLocator(0.1))
mp.tick_params(labelsize=10)
mp.grid(which='major', axis='both',
        linewidth=0.75, linestyle='-',
        color='lightgray')
mp.grid(which='minor', axis='both',
        linewidth=0.25, linestyle='-',
        color='lightgray')
mp.semilogy(y, 'o-', c='orangered',
            label='semilog')
mp.legend()
mp.tight_layout()
mp.show()

在这里插入图片描述

  • 6
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值