-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'str' object has no attribute 'zorder' #9471
Labels
Comments
`Ax.title = "HDD Temperature"`
Don't do that. Use `Ax.set_title("HDD Temperature")`
…On Wed, Oct 18, 2017 at 12:22 PM, Nico Stöckigt ***@***.***> wrote:
Bug report
I try to create a plot from temperatures over datetimes by using an
numpy.array. The plot should only be saved as PNG to be display via a
servers webserver.
The data is retrieved from a logfile that looks like:
10.09.2017 08:43:01 - 32°C
10.09.2017 10:04:01 - 33°C
10.09.2017 12:32:01 - 31°C
*Code for reproduction*
The Code is highly inspired by → https://matplotlib.org/
gallery/api/date.html#sphx-glr-gallery-api-date-py
#!/usr/bin/env python# -*- coding: utf-8 -*-import matplotlib
matplotlib.use('Agg')import matplotlib.pyplot as pltimport matplotlib.dates as mdatesimport datetime import numpy as npimport reimport os
def getDataFromLog():
hddDates = []
hddTemps = []
hddData = np.empty((0,), dtype=[('dates', 'datetime64[s]'), ('temperature', 'int64')])
with open('/var/log/hddtemp.log', 'r') as f:
for line in f:
(hd, ht) = line.strip().split(' - ')
hd = datetime.datetime.strptime(hd, '%d.%m.%Y %H:%M:%S')
ht = int(re.findall(r'\d+', ht)[0].strip())
hddEntry = np.array([(hd, ht)], dtype=hddData.dtype)
hddData = np.hstack((hddData, hddEntry))
# plt.ioff()
years = mdates.YearLocator() # every year
months = mdates.MonthLocator() # every month
days = mdates.DayLocator() # every day
dayFmt = mdates.DateFormatter('%d.%m.%Y')
monthFmt = mdates.DateFormatter('%b.%Y')
yearFmt = mdates.DateFormatter('%Y')
Date = hddData['dates'].astype('O')
Fig = plt.figure()
Ax = plt.subplot()
Ax.plot(Date)
Ax.xaxis.set_major_locator(months)
Ax.xaxis.set_major_formatter(monthFmt)
Ax.xaxis.set_minor_locator(days)
minDate = Date.min()
maxDate = Date.max()
datemin = datetime.date(minDate.year, minDate.month, 1)
datemax = datetime.date(maxDate.year, maxDate.month + 1, 1)
Ax.set_xlim(datemin, datemax)
# format the coords message box
def temperature(x):
return '$%d' % x
Ax.format_xdata = mdates.DateFormatter('%d.%m.%Y %H:%M')
Ax.format_ydata = temperature
#Ax.ylabel('temperature')
Ax.title = "HDD Temperature"
Ax.grid(True)
Fig.autofmt_xdate()
plt.show()
#plt.savefig('hddtemp.png')
Fig.savefig('hddtemp.png')
plt.close(Fig)
def main():
getDataFromLog()
if __name__ == "__main__":
main()
*Actual outcome*
Traceback (most recent call last):
File "./draw_hddtemp.py", line 75, in <module>
main()
File "./draw_hddtemp.py", line 72, in main
getDataFromLog()
File "./draw_hddtemp.py", line 67, in getDataFromLog
Fig.savefig('hddtemp_f.png')
File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1572, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2244, in print_figure
**kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 545, in print_png
FigureCanvasAgg.draw(self)
File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 464, in draw
self.figure.draw(self.renderer)
File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1143, in draw
renderer, self, dsu, self.suppressComposite)
File "/usr/lib/python2.7/dist-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/lib/python2.7/dist-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 2381, in draw
dsu = [(a.zorder, a) for a in artists]
AttributeError: 'str' object has no attribute 'zorder'
*Expected outcome*
A PNG file containing the plot corresponding to the temperatures from the
log.
*Matplotlib version*
- Operating system: Debian GNU/Linux 9.2 (stretch)
- Matplotlib version: 2.0.0+dfsg1-2
- Matplotlib backend (print(matplotlib.get_backend())): u'TkAgg'
- Python version: 2.7.13
- Jupyter version (if applicable): ---
- Other libraries: numpy:1.12.1
apt install python-matplotlib python-matplotlib-data
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#9471>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-JoBk-2mRad5C9flU9KDl2E5zAM_ks5stiWpgaJpZM4P9-9O>
.
|
Also, I should note that this code will break in December because you are adding 1 to the month. Use timedelta instead for doing date math. |
...also please try and minimize your example before writing an issue. You can often find the error that way. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
I try to create a plot from temperatures over datetimes by using an numpy.array. The plot should only be saved as PNG to be display via a servers webserver.
The data is retrieved from a logfile that looks like:
Code for reproduction
The Code is highly inspired by → https://matplotlib.org/gallery/api/date.html#sphx-glr-gallery-api-date-py
Actual outcome
Expected outcome
A PNG file containing the plot corresponding to the temperatures from the log.
Matplotlib version
print(matplotlib.get_backend())
): u'TkAgg'apt install python-matplotlib python-matplotlib-data
The text was updated successfully, but these errors were encountered: