I have been trying to add two lists of floats to a scatterplot using the Matplotlib. I have simply created a Basemap with mostly default settings. However, whenever I attempt to run the script I get the error below.
#!/usr/bin/python
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
def main():
wmap = Basemap()
wmap.drawmapboundary(fill_color='aqua')
wmap.fillcontinents(color='coral',lake_color='aqua')
wmap.drawcoastlines()
locationData = open("locationData", "r")
lats = []
lons = []
ASN = []
company = []
fileLine = locationData.readlines()
for i in fileLine:
parsedLine = i.split(",")
lats.append(float(parsedLine[0]))
lons.append(float(parsedLine[1]))
ASN.append(parsedLine[2])
company.append(parsedLine[3])
locationData.close()
x,y = wmap(lats,lons)
wmap.scatter(x,y)
plt.show()
if(__name__ == '__main__'):
main()
I receive the error:
Traceback (most recent call last):
File "mapGen.py", line 51, in <module>
main()
File "mapGen.py", line 45, in main
wmap.scatter(lats,lons)
File "/usr/lib/python3.7/site-packages /mpl_toolkits/basemap/__init__.py", line 563, in with_transform
return plotfunc(self,x,y,*args,**kwargs)
File "/usr/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py", line 3253, in scatter
self._restore_hold(ax)
File "/usr/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py", line 3229, in _restore_hold
ax._hold = self._tmp_hold
AttributeError: can't set attribute
I have tried changing around the attributes to wmap.scatter() and the variables, but there error still persists and I haven't been able to find documentation on this error. Any ideas?
This specific exception is raised when the attribute you're trying to change is a property that doesn't have a setter. It seems the basemap change is needed, adding a setter would solve the issue.
But you can change wmap.scatter(x,y) to plt.scatter(x, y) to solve it.
Related
I have a custom geoprocessing task written for me in python that takes 2 inputs - input_rows.csv and event_rows.csv - and creates a file gdb with a feature class of a join of these 2 tables.
input_rows has the x,y coordinates for the feature class.
event_rows.csv contains the attributes.
When I run it locally in ArcCatalog (10.7.1), it runs fine. If I publish it to our ArcGIS 10.81 Linux server and run that in ArcCatalog, it also runs fine. If I try to execute it thru a call in my C# application, I get a generic error on TableToTable_conversion:
<Msg time='2022-10-25T13:01:43,305' type='SEVERE' code='20010' target='export/Download_v3.GPServer' methodName='GPServerSync.CheckMessages' machine='DCP-G-XPLLAGS01.GEOPLAN.UFL.EDU' process='116658' thread='505' user='null' requestId='55b85e40-1ea9-4934-ade7-124fe4dc86c9'>Error executing tool. Download Job ID: j46c9f46dd97642e4890778604255a1fb :
Traceback (most recent call last):
File "<string>", line 248, in execute
File "<string>", line 190, in zip_GIS
File "z:\home\esri\arcgis\server\arcpy\arcpy\conversion.py", line 2272, in TableToTable
raise e
ExecuteError: ERROR 999999: Error executing function.
Failed to execute (TableToTable).
Here is the code to do the conversion:
x_coords = "S4_X"
y_coords = "S4_Y"
out_event_lyr = "event_layer"
v_scratchFolder_ = "%scratchFolder%"
# create Folder
arcpy.CreateFolder_management(v_scratchFolder_, "Geodatabase")
# create File GDB
arcpy.CreateFileGDB_management(x, gdb_name)
wkt = "PROJCS['NAD_1983_HARN_Florida_GDL_Albers',GEOGCS['GCS_North_American_1983_HARN',DATUM['D_North_American_1983_HARN',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Albers'],PARAMETER['False_Easting',400000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-84.0],PARAMETER['Standard_Parallel_1',24.0],PARAMETER['Standard_Parallel_2',31.5],PARAMETER['Latitude_Of_Origin',24.0],UNIT['Meter',1.0],AUTHORITY['EPSG',3087]]"
sr = arcpy.SpatialReference()
sr.loadFromString(wkt)
out_event_lyr = arcpy.MakeXYEventLayer_management(input_rows, x_coords, y_coords, out_event_lyr, sr)
crash_fc = arcpy.CopyFeatures_management(out_event_lyr, os.path.join("%scratchFolder%\Geodatabase", gdb_name, out_event_fc))
event_tab = arcpy.TableToTable_conversion(event_rows, os.path.join("%scratchFolder%\Geodatabase", gdb_name), "EventTab")
crash_fc_lyr = arcpy.MakeFeatureLayer_management(crash_fc, "fc_lyr")
out_event_lyr_join = arcpy.AddJoin_management(crash_fc_lyr, "REPORT_NUMBER", event_tab, "REPORT_NUMBER")
arcpy.CopyFeatures_management(out_event_lyr_join, os.path.join("%scratchFolder%\Geodatabase", gdb_name, out_event_fc1))
We changed the script to do a CopyFeatures instead of TableToTable to see if that would work but I get a different error:
ExecuteError: ERROR 000210: Cannot create output Z:\opt\esri\arcgis\server\usr\directories\arcgisjobs\export\download_v3_1_gpserver\j46744155824f44e1ad5f7c1a1a6afc71\scratch\Geodatabase\s4_mapped_crashes_gdb.gdb\att
Failed to execute (CopyFeatures).
Here is the CopyFeature version:
x_coords = "S4_X"
y_coords = "S4_Y"
out_event_lyr = "event_layer"
v_scratchFolder_ = "%scratchFolder%"
Geodatabase = v_scratchFolder_
s4_crash_gdb_gdb = Geodatabase
# create Folder
x = arcpy.CreateFolder_management(v_scratchFolder_, "Geodatabase")
arcpy.AddMessage(x)
# create File GDB
arcpy.CreateFileGDB_management(x, gdb_name)
wkt = "PROJCS['NAD_1983_HARN_Florida_GDL_Albers',GEOGCS['GCS_North_American_1983_HARN',DATUM['D_North_American_1983_HARN',SPHEROID['G RS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Albers'],PARAMETER['False_Easting',400000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-84.0],PARAMETER['Standard_Parallel_1',24.0],PARAMETER['Standard_Parallel_2',31.5],PARAMETER['Latitude_Of_Origin',24.0],UNIT['Meter',1.0],AUTHORITY['EPSG',3087]]"
sr = arcpy.SpatialReference()
sr.loadFromString(wkt)
# create GIS file in geodatabase
out_event_lyr = arcpy.MakeXYEventLayer_management(input_rows, x_coords, y_coords, out_event_lyr, sr)
crash_fc = arcpy.CopyFeatures_management(out_event_lyr, os.path.join("%scratchFolder%\Geodatabase", gdb_name, out_event_fc))
crash_fc_lyr = arcpy.MakeFeatureLayer_management(crash_fc, "fc_lyr")
out_event_lyr_join = arcpy.AddJoin_management(crash_fc_lyr, "REPORT_NUMBER", event_rows, "REPORT_NUMBER")
arcpy.CopyFeatures_management(out_event_lyr_join, os.path.join("%scratchFolder%\Geodatabase", gdb_name, out_event_fc1))
My ArcGIS and Python skills are pretty rudimentary so I'm struggling trying to figure out what the issue is. Doesn't seem like an unreasonable task I'm trying to accomplish but it has me stumped. What am I missing?
I have written a python ROS node to subscribe to two different topics and uses the ApproximateTimeSynchroniser to basically to match the messages via their timestamp and bundle these messages into one callback routine. If I use the callback to simply print out the two messages received it works fine.
However, I would like to populate a geometry_msgs/Pose message using the x and y positions from the received Pose 2D data in the callback routine.Using the code below, I have done this by making an empty Pose object in the callback routine:
#!/usr/bin/env python
import message_filters
import rospy
from laser_line_extraction.msg import LineSegmentList
from geometry_msgs.msg import Pose, Pose2D
from std_msgs.msg import Int32, Float32
rospy.init_node('simul-subscriber')
def callback(Pose2D, LineSegmentList):
pose = Pose()
pose.position.x = Pose2D.position.x
pose.position.y = Pose2D.position.y
pose.position.z = 0
#print(Pose2D, LineSegmentList, pose)
print(pose)
print(LineSegmentList)
line_segment_sub = message_filters.Subscriber('/line_segments', LineSegmentList)
pose_2D_sub = message_filters.Subscriber('/pose2D',Pose2D)
ts = message_filters.ApproximateTimeSynchronizer([line_segment_sub, pose_2D_sub], 10, 0.1, allow_headerless=True)
ts.registerCallback(callback)
rospy.spin()
Unfortunately, this gives a weird error when running this node:
[ERROR] [1535552711.709928, 1381.743000]: bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7f7af3cee9d0>>
Traceback (most recent call last):
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 75, in callback
self.signalMessage(msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 57, in signalMessage
cb(*(msg + args))
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 287, in add
self.signalMessage(*msgs)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 57, in signalMessage
cb(*(msg + args))
File "/home/elisabeth/catkin_ws/src/hector_quadrotor/hector_quadrotor_demo/python_scripts/simul-subscriber.py", line 14, in callback
pose.position.x = Pose2D.position.x
AttributeError: 'LineSegmentList' object has no attribute 'position'
This is odd as the position attribute is only referenced for the Pose 2D and not the LineSegmentList msg. I suspect this is most a python issue than a ROS issue, any help somebody could give would be much appreciated!
I am following the example found at http://wiki.ros.org/message_filters where they took two different topics image and cameraInfo and passed them into the callback function
1 import message_filters
2 from sensor_msgs.msg import Image, CameraInfo
3
4 def callback(image, camera_info):
5 # Solve all of perception here...
6
7 image_sub = message_filters.Subscriber('image', Image)
8 info_sub = message_filters.Subscriber('camera_info', CameraInfo)
9
10 ts = message_filters.TimeSynchronizer([image_sub, info_sub], 10)
11 ts.registerCallback(callback)
12 rospy.spin()
You confuse class names with object names.
The fix to your program should be straight forward.
I've changed Pose2D to pose2d, and LineSegmentList to linesegmentlist where it was necessary and comented it with # --- Change ...:
#!/usr/bin/env python
import message_filters
import rospy
from laser_line_extraction.msg import LineSegmentList
from geometry_msgs.msg import Pose, Pose2D
from std_msgs.msg import Int32, Float32
rospy.init_node('simul-subscriber')
# --- CHANGE: using proper object names instread of class names
def callback(pose2d, linesegmentlist):
pose = Pose()
# --- CHANGE: using the object
pose.position.x = pose2d.position.x
pose.position.y = pose2d.position.y
pose.position.z = 0
#print(pose2d, linesegmentlist, pose)
print(pose)
print(linesegmentlist)
line_segment_sub = message_filters.Subscriber('/line_segments', LineSegmentList)
pose_2D_sub = message_filters.Subscriber('/pose2D',Pose2D)
ts = message_filters.ApproximateTimeSynchronizer([line_segment_sub, pose_2D_sub], 10, 0.1, allow_headerless=True)
ts.registerCallback(callback)
rospy.spin()
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
plt.style.use('ggplot')
columns = ['user_id','order_dt','order_products','order_amount']
df = pd.read_csv('CDNOW_master.txt',names = columns,sep = '\s+')
df['order_date'] = pd.to_datetime(df.order_dt,format='%Y%m%d')
df['month'] = df.order_date.values.astype('datetime64[M]')
f = df.groupby('user_id')['month'].min().value_counts()
print(f)
Above is my code,my purpose is to get the value_counts of the users purchased in their first month, but only got the result of 'NoneType' object has no attribute 'fileno'.
any ideas? much appreciate
here are the traceback
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\practice\CDNOW.py", line 19, in <module>
print(f)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\core\base.py", line 51, in __str__
return self.__unicode__()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\core\series.py", line 982, in __unicode__
width, height = get_terminal_size()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\io\formats\terminal.py", line 33, in get_terminal_size
return shutil.get_terminal_size()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 1071, in get_terminal_size
size = os.get_terminal_size(sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'
I am seeing this as well.
>>> type(sys.__stdout__)
<class 'NoneType'>
I get NoneType when calling dunder stdout while I am using idle. I assume that pandas wants to determine how much to display in the results and is looking for the sys output information. In the documentation, it mentions what this is, but not how to reset it.
I did this:
sys.__stdout__ = sys.stdout
and it fixed the problem, but I have not idea if I caused problems down the line.
You may wish to try out the following.
df = pd.read_csv('CDNOW_master.txt',usecols = columns,sep = '\s+')
instead of
df = pd.read_csv('CDNOW_master.txt',names = columns,sep = '\s+')
This solved my problem. Hope it solves yours too.
I've been trying to get my Tkinter wrapper (specialised to make a game out of) to work, but it keeps throwing up an error when it tries to draw a rectangle.
Traceback:
Traceback (most recent call last):
File "C:\Users\William\Dropbox\IT\Thor\test.py", line 7, in <module>
aRectangle = thorElements.GameElement(pling,rectangleTup=(True,295,195,305,205,"blue"))
File "C:\Users\William\Dropbox\IT\Thor\thorElements.py", line 79, in __init__
self.rectangle = self.area.drawRectangle(self)
File "C:\Python33\lib\tkinter\__init__.py", line 1867, in __getattr__
return getattr(self.tk, attr)
AttributeError: 'tkapp' object has no attribute 'drawRectangle'
The sections of the code that are relevant to the question,
class GameElement():
def __init__(self,area,rectangleTup=(False,12,12,32,32,"red")):
self.area = area
self.lineTup = lineTup #Tuple containing all the data needed to create a line
if self.lineTup[0] == True:
self.kind = "Line"
self.xPos = self.lineTup[1]
self.yPos = self.lineTup[2]
self.line = self.area.drawLine(self)
And here's the actual method that draws the rectangle onto the canvas (in the class that manages the Canvas widget), earlier in the same file:
class Area():
def drawLine(self,line):
topX = line.lineTup[1]
topY = line.lineTup[2]
botX = line.lineTup[3]
botY = line.lineTup[4]
colour = line.lineTup[5]
dashTuple = (line.lineTup[6][0],line.lineTup[6][1])
return self.canvas.create_line(topX,topY,botX,botY,fill=colour,dash=dashTuple)
print("Drew Line")
All input is greatly appreciated.
The error message is meant to be self explanatory. When it says AttributeError: 'tkapp' object has no attribute 'drawRectangle', it means that you are trying to do tkapp.drawRectangle or tkapp.drawRectangle(...), but tkapp doesn't have an attribute or method named drawRectangle.
Since your code doesn't show where you create tkapp or how you created it, or where you call drawRectangle, it's impossible for us to know what the root of the problem is. Most likely it's one of the following:
tkapp isn't what you think it is
you have a typo, and meant to call drawLine rather than drawRectangle,
you intended to implement drawRectangle but didn't
I just run into a weird problem. The way I am writing my code, first I write functions on the fly in the Ipython Qt console interactively, and tweak them as necessary. Once I am satisfied with the results, I move them into a py file, to use the functions at a later time.
So, I wrote a function which is supposed to plot a histogram on screen. If I first run my py script, then call the function with the required arguments, I get an error message, which is at the very bottom of this post. If I copy and paste the function code to the qt console, and hit enter, then the function works fine after that point.
Why would this function work fine after I copy paste it to the qt console, but does not work if I directly call it after running my script with the %run script.py magic?
Thanks for any ideas!
Here is my function:
def PlotFreqHist(w_hist_list, head, span, m):
'''
Generates a frequency distribution plot
'''
if head == 30.:
tr_cond = 'Normal'
else:
tr_cond = 'Congested'
histweights = np.zeros_like(w_hist_list[0]) + 1. / w_hist_list[0].size * 100
bmap = brewer2mpl.get_map('RdYlBu', 'diverging', 10)
colors = bmap.mpl_colors
mpl.rcParams['axes.color_cycle'] = colors
fig = plt.figure(figsize=(12,8))
ax = axes()
plt.xlim(0.0,1.2)
plt.ylim(0.0,6)
plt.xlabel('Uniform Load [kips/ft]')
plt.ylabel('Frequency [%]')
plt.title('Frequency Distribution\n Number of Simulations = %i Span Length = %.0fft Traffic Condition = %s' %(m, span, tr_cond))
ax.xaxis.set_major_locator(MultipleLocator(0.1))
ax.xaxis.set_minor_locator(MultipleLocator(0.02))
ax.yaxis.set_major_locator(MultipleLocator(1.0))
ax.yaxis.set_minor_locator(MultipleLocator(0.2))
plt.grid(b=True, which='major', linewidth=1.0)
plt.grid(b=True, which='minor')
for i in xrange(len(w_hist_list)):
hist(w_hist_list[i], bins = 200, range = (0,2), normed = 0, cumulative = 0, histtype = charttype, linewidth=2.0, alpha =0.5, weights = histweights)
plt.show()
And here is the error message:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\IPython\core\ultratb.py", line 779, in structured_traceback
records = _fixed_getinnerframes(etb, context, tb_offset)
File "C:\Python27\lib\site-packages\IPython\core\ultratb.py", line 245, in _fixed_getinnerframes
records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
File "C:\Python27\lib\inspect.py", line 1043, in getinnerframes
framelist.append((tb.tb_frame,) + getframeinfo(tb, context))
File "C:\Python27\lib\inspect.py", line 1007, in getframeinfo
lines, lnum = findsource(frame)
File "C:\Python27\lib\inspect.py", line 580, in findsource
if pat.match(lines[lnum]): break
IndexError: list index out of range
ERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.
Unfortunately, your original traceback can not be constructed.