python - 构建子图
问题描述
我正在尝试创建一系列子图:
count=0
fig1, axes1 = plt.subplots(nrows=2, ncols=1, figsize=(10,80))
for x in b:
"""code gets data here as a dataframe"""
axes1[count]=q1.plot()
count=count+1
但是,这会在一个图中创建两个图而不是 2 个子图。我在 Pycharm 中使用 python 3.5。一直在为我在这里做错的事情绞尽脑汁
解决方案
您正在使用创建一个轴数组(子图)fig1, axes1 = plt.subplots(...)
。然后,当您这样做时,您将覆盖此数组的元素
axes1[count]=q1.plot()
q1.plot()
您被分配给该数组的一个元素的返回值。
axes1[count].plot(...)
如果您使用的是纯 matplotlib,您可能想要做的是使用您的轴直接绘图。当您使用 pandas 时,将您的坐标区作为参数传递给绘图函数:
count=0
fig1, axes1 = plt.subplots(nrows=2, ncols=1, figsize=(10,80))
for x in b:
"""code gets data here as a dataframe"""
q1.plot(ax=axes1[count])
count=count+1
推荐阅读
- excel - 如何围绕 Office.js Excel 事件处理程序包装 Observable
- python - ValueError:检查目标时出错:预期dense_32的形状为(1,)但得到的数组形状为(10000,)
- c# - SQL Server 中整数列表的最佳替代方案是什么?
- angularjs - 使用angularJS在按键上使用正则表达式验证表单输入字段
- html - 我想使用 python 烧瓶网络服务器在 html 站点上添加用户队列
- android - 如何在 Android 中为 Dialog 设置背景透明度?
- java - FirebaseAuth:发送获取令牌时的[重新加载] RemoteException
- database-design - 在这种情况下,使用 1 个表而不是多个表有意义吗?
- python - 在代码中集成 p4python 后如何修复 P4 客户端错误?
- javascript - window.history.back() 无法正常工作