python - Pyplot-扩展x轴
问题描述
这是我用来产生以下输出的代码:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
xedges = [27.5, 35, 42.5, 50, 57.5, 65, 72.5, 80, 87.5, 95, 102.5, 110, 117.5, 125, 132.5, 140, 147.5, 155, 162.5]
yedges = [0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380]
H = pd.read_stata ('R:/data.dta')
fig = plt.figure()
plt.imshow(H, cmap="nipy_spectral", interpolation='bilinear', origin='low',extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])
图上的 x 轴看起来非常压缩。我希望能够生成相同的图表,但 x 轴更宽,我该怎么做?
我怀疑它与“范围”参数有关,但我不确定该怎么做。
解决方案
我刚刚想通了。解决方案是在代码中将纵横比设置为“自动”,如下所示:
plt.imshow(H, cmap="nipy_spectral", interpolation='bilinear', origin='low',aspect = 'auto', extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])
推荐阅读
- python - 使用嵌套数组打印嵌套 OrderedDict 中键和值的所有路径
- linux - ASP Net Core Linux ERR_CONNECTION_REFUSED
- javascript - MathJax 未正确显示动态添加(使用 js)矩阵
- javascript - 如何在 Vue CLI 组件中使用 Multi External CDN JavaScript 文件
- laravel - Laravel Eloquent 查询返回非对象
- gpu - pytools.prefork.ExecError: error invoking 'nvcc --version': [Errno 2] No such file or directory
- java - 不支持 HTTP 版本:505
- c# - 为什么当我尝试在 RecData() 方法中接收数据时,我的 udp 客户端没有抛出异常?
- docker - Docker 运行:无效的参考格式
- python - 读取文本文件并将其解析到结构 json 文件中 - 在 json 文件中返回不需要的键和 null/dict