我是通过遍历csv文件来生成一组图,然后基于一个群生成多个图。守则如下:
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
frame=pd.read_csv('C:\\')
pdf_files = {}
for group_name, group in frame.groupby(['Allotment','Year','Month','Day'
我有一个代码,可以创建大约50个基于groupby的图表。代码如下所示:
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
with PdfPages('foo.pdf') as pdf:
for i, group in df.groupby('station_id'):
plt.figure()
fig=group.plot(x='year', y='Value',title=str(
我从一个带有子图的熊猫数据框中绘图,结果我得到了一个带有多个轴的np.array。
array([<matplotlib.axes._subplots.AxesSubplot object at blablabla>,
<matplotlib.axes._subplots.AxesSubplot object at blablabla>,
<matplotlib.axes._subplots.AxesSubplot object at blablabla>])
我想抓取这个输出来编辑标题,x标签,并将其保存为pdf。如果只有一个轴
我正在尝试使用startswith对数据文件的某些部分进行排序,这样我就可以在matplotlib上按它们的名称绘制它们。我使用:
mint = open('/Users/brand/Desktop/datafile.txt')
str = ps.DataFrame(mint)
a = str.startswith('MS')
plt.scatter(color[a], light[a], c = 'blue')
b = str.startswith('BH')
plt.scatter(color[b], light[b], c
我有一打盒子在同一个情节里,水平地排列着。我希望它们之间的间距是常数,所以在调用positions时没有设置plt.boxplot()。
对于每个框图,我希望对应的标签在X轴上有一个特定的值。我这样做:
xtickNames = plt.setp(ax, xticklabels=[str(v) for v in values])
plt.setp(xtickNames)
它可以工作,但是我在屏幕上看到了所有的输出:
agg_filter:未知阿尔法:浮动(通过1.0不透明透明)动画:真假轴: an :class:~matplotlib.axes.Axes实例背景颜色:任何matplotlib
我使用py2exe生成应用程序时没有遇到任何问题。但是,当我执行.exe时,它抛出了下一个回溯:
Traceback (most recent call last):
File "editor.py", line 25, in <module>
File "moviepy\editor.pyo", line 72, in <module>
File "<string>", line 1, in <module>
AttributeError: 'module' obje
我在保存matplotlib动画时遇到了问题。当我执行以下测试脚本时:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_ylim([0,11])
ax.set_xlim([0,100])
u, v, ims = [], [], []
u.append(0)
v.append(10)
for i in range(100):
u.append(i+
自从升级matplotlib以来,每当我尝试创建图例时都会遇到以下错误:
/usr/lib/pymodules/python2.7/matplotlib/legend.py:610: UserWarning: Legend does not support [<matplotlib.lines.Line2D object at 0x3a30810>]
Use proxy artist instead.
http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist
warnings.w
我想提取两列数据,并使用它们作为值在matplotlib上绘制直方图。我已经尽可能地密切关注了在中找到的这个答案,只是在几个方面有所不同(例如使用了SQL模块)。但是,我的脚本运行时出现错误:
Traceback (most recent call last):
File "plot_script.py", line 22, in <module>
for row in result:
TypeError: 'NoneType' object is not iterable
我的python脚本是:
import mysql.connec
我正在尝试使用matplotlib绘制一个图。我当前的日期实际上是整数,195003,195006等等。因此,当我绘制图表时,折线图并不平滑,因为在195012和195101之间有一个很大的差距。有没有办法解决这个问题?非常感谢!
import matplotlib.pyplot as plt
x = [195003,195006,195009,195012,195103,195106,195109]
y = [1,2,3,4,3,2,1]
plt.plot(x,y)
#This is the target - a smooth line chart
plt.figure(2)
实际上,我是python的新手。
当我尝试编译以下代码时:
import matplotlib.pyplot as plt
import plotly.plotly as py
# Learn about API authentication here: https://plot.ly/python/getting-started
# Find your api_key here: https://plot.ly/settings/api
x = [1,2,3,4]
y = [3,4,8,6]
plt.plot(x, 'o')
plt.plot(y)
我编写了以下脚本来绘制python列表中项目的频率。当列表是字符串时,我不能在x轴上显示实际的字符串值,并且我得到这个错误:
Traceback (most recent call last):
File "testy.py", line 15, in <module>
plt.bar([row[0] for row in votes_count], [row[1] for row in votes_count])
File "...\matplotlib\pyplot.py", line 2705, in bar
**kwa
这可能是一个更普遍的问题,因为我已经看到类似的行为与其他模块。但是,我将展示这个问题,因为我看到了模块matplotlib。我认为dir(module)列出了指定模块的所有属性。所以我可以做以下几件事:
import matplotlib
dir(matplotlib)
列出的结果中有'dateutil',但dir(matplotlib)没有列出'dates‘。但我这样做了:
import matplotlib.dates ## why does this work? `dir(matplotlib)` did not list it
dir(matplotlib)
关于,文档中说有一个类matplotlib.figure.AxesStack
AxesStack是可调用的,其中ax_stack()返回当前轴
然而,当我调用fig.ax_stack()时,我得到了错误:
AttributeError: 'Figure' object has no attribute 'ax_stack'
我尝试使用Python导入csv文件,但得到以下错误: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 5: invalid continuation byte During handling of the above exception, another exception occurred:
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-2-975331fc3025>
我在导入matplotlib时遇到问题。我使用的是: WPy64-3850和sypder。
File "D:\tkminek_local\PYTHON\DAMPING\pokus.py", line 1, in <module>
from matplotlib import pyplot as plt
File "D:\instalacky\WPy64-3850\python-3.8.5.amd64\Lib\site-packages\matplotlib\__init__.py", line 822, in <module&g