【发布时间】:2019-12-21 23:25:09
【问题描述】:
我是一名理学硕士学生,我曾经使用 OriginPro、Excel 和 Matlab 等商业软件包制作图形和绘图。尽管这些软件提供了出色的用户体验,但也存在一些主要缺点,因为它们依赖于特定的操作系统,而且通常非常昂贵。
因此,我开始使用带有 VS Code 的 matplotlib 库来学习 Python,但是我在一些库函数和语句方面遇到了一些问题,这些库函数和语句似乎是 matplotlib 和 numPy 的标准,但它不起作用。
例如,我正在为散点图制作一些模板,但我无法控制小刻度,因为它无法识别语句 xaxix 和 yaxix:
代码示例:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, AutoMinorLocator
.
.
.
fig = plt.figure(figsize=(x_pixels/my_dpi, y_pixels/my_dpi), dpi=my_dpi)
ax = plt.scatter(x*format_x, y*format_y, s = size, alpha = transparency, color = color, label = legend_text)
.
.
.
# Major Ticks
plt.tick_params(axis = 'both', which = 'major', length = majorT_length, direction = majorT_direction, color = majorT_color, labelsize = label_size, top = 'on', right = 'on')
# Minor Ticks
plt.minorticks_on()
plt.tick_params(axis='both', which='minor', length = minorT_length, direction = minorT_direction, color = minorT_color, top = 'on', right = 'on')
ax.yaxis.set_minor_locator(AutoMinorLocator(2))
ax.xaxis.set_minor_locator(AutoMinorLocator(2))
# Figure Layout
plt.tight_layout()
plt.savefig(output_file, dpi=my_dpi, bbox_inches=borders)
plt.show()
终端显示此错误:
File "c:/Users/luagu/Desktop/Python Matplotlib Training/Scatter_Template.py", line 128, in <module>
ax.yaxis.set_minor_locator(AutoMinorLocator(2))
AttributeError: 'PathCollection' object has no attribute 'yaxis'
我做错了什么?
提前致谢!
【问题讨论】:
-
请直接包含错误信息,不要作为图像。
标签: python matplotlib visual-studio-code