- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在绘制 Pandas 系列数据,它记录了 1981 年每周“事件”的总和。该系列名为“weekly_data”。
1981-03-16 1826
1981-03-23 1895
1981-03-30 1964
1981-04-06 1978
1981-04-13 2034
1981-04-20 2073
1981-04-27 2057
dtype: int64
我想按年和按周放置刻度。当我尝试绘制它时,我收到一个 AttributeError:
fig = plt.figure(figsize=(12,5))
ax = plt.subplots(111)
plt.plot(weekly_data, color = 'green' )
yloc = YearLocator()
mloc = MonthLocator()
ax.xaxis.set_major_locator(yloc)
ax.xaxis.set_minor_locator(mloc)
ax.grid(True)
plt.show()
错误是
AttributeError Traceback (most recent call last)
<ipython-input-92-843dbab30ed7> in <module>()
6 yloc = YearLocator()
7 mloc = MonthLocator()
----> 8 ax.xaxis.set_major_locator(yloc)
9 ax.xaxis.set_minor_locator(mloc)
10 ax.grid(True)
AttributeError: 'tuple' object has no attribute 'xaxis'
我该如何解决这个问题?
编辑:跟随 Mike Mueller,上面的错误是 plt.subplot(111)
。但是,我仍然无法让每周滴答声正常工作。也许我们需要使用 ax.set_xticks(major_ticks)
或 ax.set_xticks(minor_ticks, minor=True)
这是我从 1991 年开始绘制的 pandas 系列数据
Datetime
1990-12-23 1980
1990-12-30 1860
1991-01-06 1761
1991-01-13 1792
1991-01-20 1825
....
dtype: int64
这是代码
fig = plt.figure(figsize=(12,5))
ax = plt.subplot(111)
plt.plot(weekly_data1991, color = 'green' )
yloc = YearLocator()
mloc = MonthLocator()
ax.xaxis.set_major_locator(yloc)
ax.xaxis.set_minor_locator(mloc)
ax.grid(True)
plt.show()
这是绘图输出
我自己也很困惑
最佳答案
您正在创建 111 个子图。变化:
ax = plt.subplots(111)
进入:
ax = plt.subplot(111)
你应该可以。它创建一个由一行、一列和一个子图组成的子图数组。例如,这个:
plt.subplot(231)
plt.subplot(236)
在 2 行 3 列的数组中创建子图 1 和子图 6:
您可以通过以下方式使月份可见:
ax.xaxis.set_minor_formatter(matplotlib.dates.DateFormatter('%B'))
年份和月份打印在彼此之上。一种解决方案是将年份放在顶部,将月份放在底部:
ax.xaxis.set_tick_params(labeltop='on', labelbottom='off')
使用:
mloc = matplotlib.dates.MonthLocator(range(1, 12, 4))
仅每四个月显示一次。
关于python - Matplotlib,绘制 pandas 系列 : AttributeError: 'tuple' object has no attribute 'xaxis' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34388800/
我遇到了这两个错误,“AttributeError:在 DataLoader 工作进程 0 中捕获 AttributeError”,“AttributeError:模块“torchvision.tra
以下是我的代码。在最后一行中,我无法将Items[node.ind].v值设置为我想要的node.v,并收到错误。我不知道出了什么问题,但一定是基于语法,因为使用node.v+=1这样的语句也会显示相
我们准备了以下python脚本来显示word表格中的图片。 import matplotlib.pyplot as plt import pylab import win32com.client as
我需要一种方法来获取 TensorFlow 中任何类型层(即 Dense、Conv2D 等)的输出张量的形状。根据文档,有 output_shape 属性可以解决这个问题。但是,每次我访问它时,我都会
除了我之前的问题,关于如何在 Python 中打开 csv 文件,我仍然没有成功地做到这一点,并且从一个错误到另一个错误。 我的Python代码如下: @app.route("/admin", met
这是我在Google Colab中使用的代码。当我打这些电话的时候。我收到以下错误。这很奇怪。我以前从来没有见过这个问题。有没有人能帮我一下?我是不是做错了什么?
我想将Excel中的数据添加到词典中。但是,当我使用.append(TOTAL_SALES)时出现错误,当然,如果我使用+=TOTAL_SALES,则没有问题,只是我获得的是总和,而不是3个单独月份的
我想将Excel中的数据添加到词典中。但是,当我使用.append(TOTAL_SALES)时出现错误,当然,如果我使用+=TOTAL_SALES,则没有问题,只是我获得的是总和,而不是3个单独月份的
我正在尝试使用 gr_modtool.py 在 gnuradio 中创建一个新的 DSP 模块。 gnuradio 版本是 3.3.0。我在 include 文件夹中的 abc.h 文件中有以下代码
AttributeError:尝试在序列化器 UserKeywordSerializer 上获取字段 user 的值时出现 AttributeError。序列化程序字段可能命名不正确,并且与 Quer
我有以下使用Chatterbot第三方库的代码:。当我尝试使用代码时,从Visual Studio收到如下错误:。我安装了以下程序包:。我尝试了使用Python3.9和3.11以及Chatterbot
我有以下使用Chatterbot第三方库的代码:。当我尝试使用代码时,从Visual Studio收到如下错误:。我安装了以下程序包:。我尝试了使用Python3.9和3.11以及Chatterbot
我有以下使用Chatterbot第三方库的代码:。当我尝试使用代码时,从Visual Studio收到如下错误:。我安装了以下程序包:。我尝试了使用Python3.9和3.11以及Chatterbot
通常,当我尝试使用BeautifulSoup解析网页时,BeautifulSoup函数会得到NONE结果,否则就会引发AttributeError。。以下是一些独立的(即,由于数据是硬编码的,不需要访
通常,当我尝试使用BeautifulSoup解析网页时,BeautifulSoup函数会得到NONE结果,否则就会引发AttributeError。。以下是一些独立的(即,由于数据是硬编码的,不需要访
我试图配置预提交挂接,在运行预提交运行--所有文件时,我收到以下错误:。我已尝试升级pip以解决此问题pip安装--升级pip,但我收到另一个错误:。我尝试检查PIP和PIP3的版本,但现在我也收到了
我收到一个 AttributeError 我似乎无法解决。我正在处理两个类(class)。 第一个类就是这样。 class Partie: def __init__(self):
在 Django (1.4) 中迁移 South (0.7.5) 时,我遇到了这个错误。我最近将时区设置更改为 false,即 USE_TZ = False 以解决另一个问题。有任何想法吗?谢谢 ~/
当我尝试在两个序列化程序之间创建嵌套关系时出现 AttributeError。奇怪的是,我正在做与另一个 API 完全相同的事情,但这次我没有让它工作。这是代码: class UserSerializ
试图获得 manytomany django 中的关系,但我收到以下错误 - Got AttributeError when attempting to get a value for field n
我是一名优秀的程序员,十分优秀!