Related
I'm trying to make a 3d contour plot using countourfcommand in Matplotlib.
Here's the variable distribution:
I'm trying to plot the contour over 3 sides of a cube:
plt.close('all')
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.pbaspect = [1.0, 1.0, 1.0]
levels = np.linspace(0,1,10)
cset = [[],[],[]]
n=0
for i in range(0,m-1):
for j in range(0,m-1):
znum[i,j]=DELTAcrit[n]
n+=1
cset[0] = ax.contourf(xnum, ynum, znum, zdir='z', offset=2*np.pi,
levels=levels,cmap='jet',antialiased=True)
for i in range(0,m-1):
for j in range(0,m-1):
znum[i,j]=DELTAcrit[n]
n+=1
cset[1] = ax.contourf(znum, xnum, ynum, zdir='x', offset=2*np.pi,
levels=levels,cmap='jet',antialiased=True)
for i in range(0,m-1):
for j in range(0,m-1):
znum[i,j]=DELTAcrit[n]
n+=1
cset[2] = ax.contourf(xnum, znum, ynum, zdir='y', offset=2*np.pi,
levels=levels,cmap='jet',antialiased=True)
# setting 3D-axis-limits:
ax.set_xlim3d(0,2*np.pi)
ax.set_ylim3d(0,2*np.pi)
ax.set_zlim3d(0,2*np.pi)
ax.set_xticks([0., .5*np.pi, np.pi, 1.5*np.pi, 2*np.pi])
ax.set_xticklabels(["$0$", r"$\frac{1}{2}\pi$",
r"$\pi$", r"$\frac{3}{2}\pi$", r"$2\pi$"])
ax.set_yticks([0., .5*np.pi, np.pi, 1.5*np.pi, 2*np.pi])
ax.set_yticklabels(["$0$", r"$\frac{1}{2}\pi$",
r"$\pi$", r"$\frac{3}{2}\pi$", r"$2\pi$"])
ax.set_zticks([0., .5*np.pi, np.pi, 1.5*np.pi, 2*np.pi])
ax.set_zticklabels(["$0$", r"$\frac{1}{2}\pi$",
r"$\pi$", r"$\frac{3}{2}\pi$", r"$2\pi$"])
ax.view_init(25, 45)
fig.subplots_adjust(bottom=-0.2,top=0.7)
cb = fig.colorbar(cset[0], shrink=0.7)
plt.show()
When I change the levels variable to a numpy.linspace with 3 or 5 levels it goes ok.
When I try like in the example with ten levels, like the one in the example I've just showed I got the following error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
246
247 if 'png' in formats:
--> 248 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
249 if 'retina' in formats or 'png2x' in formats:
250 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
130 FigureCanvasBase(fig)
131
--> 132 fig.canvas.print_figure(bytes_io, **kw)
133 data = bytes_io.getvalue()
134 if fmt == 'svg':
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2191 else suppress())
2192 with ctx:
-> 2193 self.figure.draw(renderer)
2194
2195 bbox_inches = self.figure.get_tightbbox(
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1861
1862 self.patch.draw(renderer)
-> 1863 mimage._draw_list_compositing_images(
1864 renderer, self, artists, self.suppressComposite)
1865
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py in draw(self, renderer)
443 for axis in self._get_axis_list()) + 1
444 for i, col in enumerate(
--> 445 sorted(self.collections,
446 key=lambda col: col.do_3d_projection(renderer),
447 reverse=True)):
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py in <lambda>(col)
444 for i, col in enumerate(
445 sorted(self.collections,
--> 446 key=lambda col: col.do_3d_projection(renderer),
447 reverse=True)):
448 col.zorder = zorder_offset + i
c:\users\rapha\pycharmprojects\vortexpy\venv\lib\site-packages\mpl_toolkits\mplot3d\art3d.py in do_3d_projection(self, renderer)
766 key=lambda x: x[0], reverse=True)
767
--> 768 zzs, segments_2d, self._facecolors2d, self._edgecolors2d, idxs = \
769 zip(*z_segments_2d)
770
ValueError: not enough values to unpack (expected 5, got 0)
Thanks for the help!
My code for gradient calculation is as follows :
from skimage.feature import canny
import numpy as np
def Canny_detector(img):
import cv2
from scipy.ndimage.filters import convolve
import math
blur = cv2.GaussianBlur(img, (5, 5), 1.4)
Kx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], np.float32)
Ky = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]], np.float32)
Ix = convolve(blur, Kx)
Iy = convolve(blur, Ky)
G = np.hypot(Ix, Iy)
theta = np.arctan2(Iy, Ix)
plt.imshow(G, cmap=plt.cm.gray)
return
canny_imgs = []
for img in plates:
Canny_detector(img)
Here the plates contain information about 6 images in form of a 2D array (Gray scale)
The error when executing the above code is :
ValueError Traceback (most recent call last)
E:\Programs\anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)
E:\Programs\anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
246
247 if 'png' in formats:
--> 248 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
249 if 'retina' in formats or 'png2x' in formats:
250 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
E:\Programs\anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt,
bbox_inches, **kwargs)
130 FigureCanvasBase(fig)
131
--> 132 fig.canvas.print_figure(bytes_io, **kw)
133 data = bytes_io.getvalue()
134 if fmt == 'svg':
E:\Programs\anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename,
dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
2098 else suppress())
2099 with ctx:
-> 2100 self.figure.draw(renderer)
2101 bbox_artists = kwargs.pop("bbox_extra_artists", None)
2102 bbox_inches = self.figure.get_tightbbox(renderer,
E:\Programs\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer,
*args, **kwargs)
36 renderer.start_filter()
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
40 if artist.get_agg_filter() is not None:
E:\Programs\anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1733
1734 self.patch.draw(renderer)
-> 1735 mimage._draw_list_compositing_images(
1736 renderer, self, artists, self.suppressComposite)
1737
E:\Programs\anaconda3\lib\site-packages\matplotlib\image.py in
_draw_list_compositing_images(renderer, parent, artists, suppress_composite)
135 if not_composite or not has_images:
136 for a in artists:
--> 137 a.draw(renderer)
138 else:
139 # Composite any adjacent images together
E:\Programs\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args,
**kwargs)
36 renderer.start_filter()
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
40 if artist.get_agg_filter() is not None:
E:\Programs\anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2628 renderer.stop_rasterizing()
2629
-> 2630 mimage._draw_list_compositing_images(renderer, self, artists)
2631
2632 renderer.close_group('axes')
E:\Programs\anaconda3\lib\site-packages\matplotlib\image.py in
_draw_list_compositing_images(renderer,
parent, artists, suppress_composite)
135 if not_composite or not has_images:
136 for a in artists:
--> 137 a.draw(renderer)
138 else:
139 # Composite any adjacent images together
E:\Programs\anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args,
**kwargs)
36 renderer.start_filter()
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
40 if artist.get_agg_filter() is not None:
E:\Programs\anaconda3\lib\site-packages\matplotlib\image.py in draw(self, renderer, *args, **kwargs)
623 self._draw_unsampled_image(renderer, gc)
624 else:
--> 625 im, l, b, trans = self.make_image(
626 renderer, renderer.get_image_magnification())
627 if im is not None:
E:\Programs\anaconda3\lib\site-packages\matplotlib\image.py in make_image(self, renderer,
magnification, unsampled)
912 bbox = Bbox(np.array([[x1, y1], [x2, y2]]))
913 transformed_bbox = TransformedBbox(bbox, trans)
--> 914 return self._make_image(
915 self._A, bbox, transformed_bbox,
916 self.get_clip_box() or self.axes.bbox,
E:\Programs\anaconda3\lib\site-packages\matplotlib\image.py in _make_image(self, A, in_bbox,
out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)
476 A_scaled += 0.1
477 # resample the input data to the correct resolution and shape
--> 478 A_resampled = _resample(self, A_scaled, out_shape, t)
479 # done with A_scaled now, remove from namespace to be sure!
480 del A_scaled
E:\Programs\anaconda3\lib\site-packages\matplotlib\image.py in _resample(image_obj, data, out_shape,
transform, resample, alpha)
195 if resample is None:
196 resample = image_obj.get_resample()
--> 197 _image.resample(data, out, transform,
198 _interpd_[interpolation],
199 resample,
ValueError: Unsupported dtype
<Figure size 432x288 with 1 Axes>
The final error is Unsupported data type. Is that any problem with the matplotlib imshow() method. I spent a lot of time checking for the error I was not able to figure it out. Can anyone please tell me how to rectify this?
Thank you!
The below code suddenly stated producing error. It was working fine earlier. I just reinstalled seaborn package.
plt.figure(figsize=(26,16))
sns.scatterplot(
x="tsne-2d-one",
y="tsne-2d-two",
hue="label",
palette=sns.color_palette("hls", 14),
data=df_subset,
legend="full",
alpha=1,
s=100
)
Traceback:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
c:\<path>_venv\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)
c:\<path>_venv\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
246
247 if 'png' in formats:
--> 248 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
249 if 'retina' in formats or 'png2x' in formats:
250 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
c:\<path>_venv\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
130 FigureCanvasBase(fig)
131
--> 132 fig.canvas.print_figure(bytes_io, **kw)
133 data = bytes_io.getvalue()
134 if fmt == 'svg':
c:\<path>_venv\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2191 else suppress())
2192 with ctx:
-> 2193 self.figure.draw(renderer)
2194
2195 bbox_inches = self.figure.get_tightbbox(
c:\<path>_venv\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
c:\<path>_venv\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1861
1862 self.patch.draw(renderer)
-> 1863 mimage._draw_list_compositing_images(
1864 renderer, self, artists, self.suppressComposite)
1865
c:\<path>_venv\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
c:\<path>_venv\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
c:\<path>_venv\lib\site-packages\matplotlib\cbook\deprecation.py in wrapper(*inner_args, **inner_kwargs)
409 else deprecation_addendum,
410 **kwargs)
--> 411 return func(*inner_args, **inner_kwargs)
412
413 return wrapper
c:\<path>_venv\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2746 renderer.stop_rasterizing()
2747
-> 2748 mimage._draw_list_compositing_images(renderer, self, artists)
2749
2750 renderer.close_group('axes')
c:\<path>_venv\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
c:\<path>_venv\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
c:\<path>_venv\lib\site-packages\matplotlib\collections.py in draw(self, renderer)
929 def draw(self, renderer):
930 self.set_sizes(self._sizes, self.figure.dpi)
--> 931 Collection.draw(self, renderer)
932
933
c:\<path>_venv\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
c:\<path>_venv\lib\site-packages\matplotlib\collections.py in draw(self, renderer)
383 else:
384 combined_transform = transform
--> 385 extents = paths[0].get_extents(combined_transform)
386 if (extents.width < self.figure.bbox.width
387 and extents.height < self.figure.bbox.height):
c:\<path>_venv\lib\site-packages\matplotlib\path.py in get_extents(self, transform, **kwargs)
601 xys.append(curve([0, *dzeros, 1]))
602 xys = np.concatenate(xys)
--> 603 return Bbox([xys.min(axis=0), xys.max(axis=0)])
604
605 def intersects_path(self, other, filled=True):
c:\<path>_venv\lib\site-packages\numpy\core\_methods.py in _amin(a, axis, out, keepdims, initial, where)
32 def _amin(a, axis=None, out=None, keepdims=False,
33 initial=_NoValue, where=True):
---> 34 return umr_minimum(a, axis, None, out, keepdims, initial, where)
35
36 def _sum(a, axis=None, dtype=None, out=None, keepdims=False,
ValueError: zero-size array to reduction operation minimum which has no identity
Note: df_subset is not empty, I checked. It has 3 columns "tsne-2d-one", "tsne-2d-two", "label"
"tsne-2d-one", "tsne-2d-two" contains float datatype values
"label" has String/Object data type values
Sample data:
tsne-2d-one,tsne-2d-two,label
-14.02892,-24.425629,A_A-A
-13.000096,-23.515806,A_A-A
-14.205202,-24.717735,A_A-A
-15.494256,-25.991783,A_A-A
-13.5905905,-23.419744,A_A-A
-13.350816,-25.939915,A_A-A
-12.438069,-24.727852,A_A-A
-13.54109,-26.080505,A_A-A
-14.834715,-26.33772,A_A-A
-13.562927,-23.37612,A_A-A
-15.59718,-24.024368,A_A-A
-14.931401,-22.854977,A_A-A
-15.655616,-24.41179,A_A-A
-15.716855,-25.620882,A_A-A
-15.219434,-23.031553,A_A-A
2.084894,-14.178911,B_B
5.5166216,-12.401592,B_B
2.0064962,-14.086351,B_B
5.5460343,1.7539215,B_B
5.002867,-13.499105,B_B
-0.13123433,0.9796202,B_B
7.7138877,-7.102608,B_B
-0.119276464,0.99467605,B_B
6.679522,1.4599445,B_B
4.96602,-13.200384,B_B
9.150655,-3.64276,B_B
10.205461,-6.4425406,B_B
9.038797,-3.5547273,B_B
7.0086393,1.1566005,B_B
9.934251,-6.873103,B_B
-11.11679,-11.341377,C_C C
-14.512915,-8.015724,C_C C
-9.953341,-11.557578,C_C C
-16.696735,-6.1155863,C_C C
-15.87594,-8.795022,C_C C
-11.377112,-14.174167,C_C C
-13.324324,-9.64841,C_C C
-11.897048,-13.814134,C_C C
-16.109194,-11.869152,C_C C
-16.046644,-8.998125,C_C C
-9.286824,-14.231626,C_C C
-12.704834,-7.5153055,C_C C
-9.349987,-13.253436,C_C C
-18.200735,-7.0271044,C_C C
-12.994204,-6.0151153,C_C C
-3.0917523,-10.06981,D_D_1
4.6217837,-10.767031,D_D_1
-3.1154654,-10.096936,D_D_1
5.0603623,1.1476644,D_D_1
3.369002,-11.283088,D_D_1
-5.780945,-7.966547,D_D_1
6.6392574,-8.486886,D_D_1
-5.7979536,-7.9725084,D_D_1
5.7012763,0.1932977,D_D_1
3.4227533,-11.3441305,D_D_1
-4.905956,-10.156104,D_D_1
5.8067675,-9.307196,D_D_1
-4.96808,-10.07095,D_D_1
6.28622,0.08598101,D_D_1
5.3993483,-9.526921,D_D_1
-11.131304,-11.375446,E_E_E
-14.445314,-8.006492,E_E_E
-9.945171,-11.480152,E_E_E
-16.731579,-6.1148796,E_E_E
-15.929554,-8.714455,E_E_E
-11.266886,-14.26166,E_E_E
-13.352065,-9.705651,E_E_E
-12.172098,-13.885426,E_E_E
-15.697548,-11.84327,E_E_E
-15.805679,-8.887896,E_E_E
-9.271222,-14.296528,E_E_E
-12.608987,-7.5177,E_E_E
-9.163923,-13.434417,E_E_E
-18.181078,-6.843873,E_E_E
-12.912988,-6.0278206,E_E_E
-1.5422965,-7.8732953,F_F_F
3.1139162,-8.750587,F_F_F
-2.028107,-7.784009,F_F_F
2.9877954,-1.4773916,F_F_F
1.7015373,-9.468788,F_F_F
-4.2344203,-5.2941556,F_F_F
5.2705426,-6.563142,F_F_F
-4.2245245,-5.600589,F_F_F
4.684833,-1.3839812,F_F_F
1.722953,-9.421918,F_F_F
-1.1982858,-4.9888654,F_F_F
3.6919396,-6.494554,F_F_F
-2.0073545,-5.178361,F_F_F
3.9441528,-2.738101,F_F_F
2.5451581,-6.1722994,F_F_F
-1.120436,-7.3399386,G_G_G_G
2.8947587,-8.145696,G_G_G_G
-1.4918948,-7.1562057,G_G_G_G
2.9648385,-1.7110974,G_G_G_G
1.5439045,-8.104277,G_G_G_G
-3.5719488,-4.901991,G_G_G_G
4.9950256,-6.279537,G_G_G_G
-3.4592612,-5.118906,G_G_G_G
4.573509,-1.6888899,G_G_G_G
1.4670004,-8.103425,G_G_G_G
-1.326964,-4.7369046,G_G_G_G
3.5509024,-6.1993237,G_G_G_G
-1.9852517,-4.7963614,G_G_G_G
3.8905938,-2.847331,G_G_G_G
2.3077533,-6.1591887,G_G_G_G
-0.6611299,14.413035,H_H
1.6424932,16.130213,H_H
-0.7701603,14.268575,H_H
2.9109209,8.180244,H_H
0.5201868,15.787671,H_H
-1.6890637,12.033475,H_H
2.8793135,16.313625,H_H
-1.6425153,11.930886,H_H
4.051731,8.0262375,H_H
0.43125528,15.851444,H_H
-0.049206052,12.614705,H_H
2.4294627,15.448605,H_H
-0.1478604,12.405042,H_H
3.6674721,8.151972,H_H
1.3558089,14.236326,H_H
-11.285671,15.540629,I_I_I
-9.562131,15.355534,I_I_I
-11.530592,15.769008,I_I_I
-13.046774,14.795182,I_I_I
-10.370458,15.011783,I_I_I
-12.224443,17.218636,I_I_I
-9.128062,16.107723,I_I_I
-12.329284,17.033316,I_I_I
-13.2455635,15.28421,I_I_I
-10.374858,15.010645,I_I_I
-11.048521,17.406425,I_I_I
-9.423859,16.605726,I_I_I
-11.302727,17.159101,I_I_I
-13.303642,14.898152,I_I_I
-10.067334,17.044987,I_I_I
19.458284,3.601622,J_J
18.161573,1.9801935,J_J
19.400095,4.1047544,J_J
16.417835,5.31509,J_J
18.94254,2.32699,J_J
18.529085,4.935621,J_J
16.578032,2.6348052,J_J
18.3073,5.0299187,J_J
16.369411,4.8019056,J_J
18.929241,2.3260906,J_J
18.18062,3.939813,J_J
16.98714,2.6408002,J_J
17.972517,4.1568704,J_J
16.239166,4.6899467,J_J
17.585348,2.8919232,J_J
-20.025661,8.026763,K_K_K
-20.538462,6.0866313,K_K_K
-19.686363,8.2460785,K_K_K
-18.748287,9.191302,K_K_K
-20.795744,7.023851,K_K_K
-17.74393,7.074227,K_K_K
-19.303535,5.2147784,K_K_K
-17.688332,7.3439727,K_K_K
-17.846653,8.789439,K_K_K
-20.777353,7.0788684,K_K_K
-18.925882,7.140357,K_K_K
-19.634892,5.644755,K_K_K
-18.661663,7.5221934,K_K_K
-18.29901,8.960838,K_K_K
-19.38654,6.43482,K_K_K
13.265437,15.976807,L_L_L
13.597595,19.052914,L_L_L
13.323307,16.138601,L_L_L
12.454088,17.811083,L_L_L
13.339949,19.46192,L_L_L
14.46764,15.587214,L_L_L
14.454488,18.439106,L_L_L
14.335033,15.607529,L_L_L
12.673782,17.41954,L_L_L
13.322454,19.446009,L_L_L
15.088017,16.46231,L_L_L
15.003597,18.347887,L_L_L
14.939234,16.422993,L_L_L
13.032935,17.582718,L_L_L
15.379603,18.11169,L_L_L
2.9893792,11.708033,M_M
4.0582185,14.155455,M_M
2.8813481,11.428211,M_M
2.9041388,8.880342,M_M
4.0471163,13.003807,M_M
-0.24122916,10.381815,M_M
3.4628656,15.878884,M_M
-0.17790422,10.348041,M_M
4.228249,8.942132,M_M
4.1144986,13.007208,M_M
1.0553777,11.241994,M_M
3.0545413,14.678934,M_M
1.1478767,10.947674,M_M
3.724015,9.194509,M_M
2.356918,13.5421915,M_M
19.131111,-8.112185,N_N_N
20.842833,-8.569077,N_N_N
19.030348,-8.294446,N_N_N
22.435442,-8.890868,N_N_N
20.483664,-8.155657,N_N_N
18.633186,-9.510608,N_N_N
20.852346,-9.7075,N_N_N
18.776926,-9.64985,N_N_N
22.413244,-9.279601,N_N_N
20.41144,-8.146459,N_N_N
19.47922,-10.565168,N_N_N
20.925726,-10.302838,N_N_N
19.37557,-10.4150505,N_N_N
22.429592,-9.683258,N_N_N
20.584888,-10.687437,N_N_N
Problem is related to a matplotlib regression in 3.3.1.
Original seaborn issue (closed)
Solution is to pin matplotlib to 3.3.0 until 3.3.2 is released, although the next release of seaborn will include a workaround.
Update (9/10/20): Seaborn 0.11.0 is now available that contains the workaround to make scatterplots work even with matplotlib 3.3.1.
I've noticed the same error mentioned originally by #Hitsesh Somani is occurring even for some of the example code snippets given on Seaborn's official site (https://seaborn.pydata.org/generated/seaborn.scatterplot.html).
For example the below example, copied and pasted directly from Seaborn, gives the same error as mentioned by #Hitesh Somani:
import seaborn as sns; sns.set()
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
ax = sns.scatterplot(x="total_bill", y="tip", hue="time", data=tips)
the above will return the following error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
c:\users\will\desktop\new folder\tester\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)
c:\users\will\desktop\new folder\tester\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
246
247 if 'png' in formats:
--> 248 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
249 if 'retina' in formats or 'png2x' in formats:
250 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
c:\users\will\desktop\new folder\tester\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
130 FigureCanvasBase(fig)
131
--> 132 fig.canvas.print_figure(bytes_io, **kw)
133 data = bytes_io.getvalue()
134 if fmt == 'svg':
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2191 else suppress())
2192 with ctx:
-> 2193 self.figure.draw(renderer)
2194
2195 bbox_inches = self.figure.get_tightbbox(
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1861
1862 self.patch.draw(renderer)
-> 1863 mimage._draw_list_compositing_images(
1864 renderer, self, artists, self.suppressComposite)
1865
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\cbook\deprecation.py in wrapper(*inner_args, **inner_kwargs)
409 else deprecation_addendum,
410 **kwargs)
--> 411 return func(*inner_args, **inner_kwargs)
412
413 return wrapper
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2746 renderer.stop_rasterizing()
2747
-> 2748 mimage._draw_list_compositing_images(renderer, self, artists)
2749
2750 renderer.close_group('axes')
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\collections.py in draw(self, renderer)
929 def draw(self, renderer):
930 self.set_sizes(self._sizes, self.figure.dpi)
--> 931 Collection.draw(self, renderer)
932
933
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
39 renderer.start_filter()
40
---> 41 return draw(artist, renderer, *args, **kwargs)
42 finally:
43 if artist.get_agg_filter() is not None:
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\collections.py in draw(self, renderer)
383 else:
384 combined_transform = transform
--> 385 extents = paths[0].get_extents(combined_transform)
386 if (extents.width < self.figure.bbox.width
387 and extents.height < self.figure.bbox.height):
c:\users\will\desktop\new folder\tester\lib\site-packages\matplotlib\path.py in get_extents(self, transform, **kwargs)
601 xys.append(curve([0, *dzeros, 1]))
602 xys = np.concatenate(xys)
--> 603 return Bbox([xys.min(axis=0), xys.max(axis=0)])
604
605 def intersects_path(self, other, filled=True):
c:\users\will\desktop\new folder\tester\lib\site-packages\numpy\core\_methods.py in _amin(a, axis, out, keepdims, initial, where)
41 def _amin(a, axis=None, out=None, keepdims=False,
42 initial=_NoValue, where=True):
---> 43 return umr_minimum(a, axis, None, out, keepdims, initial, where)
44
45 def _sum(a, axis=None, dtype=None, out=None, keepdims=False,
ValueError: zero-size array to reduction operation minimum which has no identity
<Figure size 432x288 with 1 Axes>
Where I'm on a Windows 10 machine, with:
jupyter core==4.6.3
jupyter-notebook==6.1.3
ipython==7.18.1
matplotlib==3.3.1
numpy==1.19.1
pandas==1.1.1
seaborn==0.10.1
and Python v3.8.5.
Seconding #Brock, there is an error in the matplotlib regression. Changing back to matplotlib 3.3.0, with the conda command below, solved the problem for me.
conda install -c conda-forge matplotlib=3.3.0
This is my DataFrame obtained importing from an Excel .xls
0 1
664 2017-12-07 19:08:54 1.1377
665 2017-12-07 19:10:31 1.1374
666 2017-12-07 19:12:17 1.1377
667 2017-12-07 19:13:28 1.1377
668 2017-12-07 19:15:25 1.1379
I think is correclty typed
0 datetime64[ns]
1 float64
dtype: object
However it does not plot with ax = _df.plot() because of some error. Any idea why?
This is my first hour in Pandas, sorry if it's classic question, but I saw only not relevant answers on this ValueError: ordinal must be >= 1
Thanks for your inputs
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-24-ca306a836171> in <module>()
----> 1 ax = _df.plot()
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2671 fontsize=fontsize, colormap=colormap, table=table,
2672 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2673 sort_columns=sort_columns, **kwds)
2674 __call__.__doc__ = plot_frame.__doc__
2675
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
1898 yerr=yerr, xerr=xerr,
1899 secondary_y=secondary_y, sort_columns=sort_columns,
-> 1900 **kwds)
1901
1902
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
1725 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
1726
-> 1727 plot_obj.generate()
1728 plot_obj.draw()
1729 return plot_obj.result
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in generate(self)
258
259 for ax in self.axes:
--> 260 self._post_plot_logic_common(ax, self.data)
261 self._post_plot_logic(ax, self.data)
262
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in _post_plot_logic_common(self, ax, data)
393 self._apply_axis_properties(ax.xaxis, rot=self.rot,
394 fontsize=self.fontsize)
--> 395 self._apply_axis_properties(ax.yaxis, fontsize=self.fontsize)
396
397 if hasattr(ax, 'right_ax'):
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in _apply_axis_properties(self, axis, rot, fontsize)
466
467 def _apply_axis_properties(self, axis, rot=None, fontsize=None):
--> 468 labels = axis.get_majorticklabels() + axis.get_minorticklabels()
469 for label in labels:
470 if rot is not None:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in get_majorticklabels(self)
1189 def get_majorticklabels(self):
1190 'Return a list of Text instances for the major ticklabels'
-> 1191 ticks = self.get_major_ticks()
1192 labels1 = [tick.label1 for tick in ticks if tick.label1On]
1193 labels2 = [tick.label2 for tick in ticks if tick.label2On]
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in get_major_ticks(self, numticks)
1318 'get the tick instances; grow as necessary'
1319 if numticks is None:
-> 1320 numticks = len(self.get_major_locator()())
1321 if len(self.majorTicks) < numticks:
1322 # update the new tick label properties from the old
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in __call__(self)
984 def __call__(self):
985 'Return the locations of the ticks'
--> 986 self.refresh()
987 return self._locator()
988
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in refresh(self)
1004 def refresh(self):
1005 'Refresh internal information based on current limits.'
-> 1006 dmin, dmax = self.viewlim_to_dt()
1007 self._locator = self.get_locator(dmin, dmax)
1008
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in viewlim_to_dt(self)
761 vmin, vmax = vmax, vmin
762
--> 763 return num2date(vmin, self.tz), num2date(vmax, self.tz)
764
765 def _get_unit(self):
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in num2date(x, tz)
399 tz = _get_rc_timezone()
400 if not cbook.iterable(x):
--> 401 return _from_ordinalf(x, tz)
402 else:
403 x = np.asarray(x)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in _from_ordinalf(x, tz)
252
253 ix = int(x)
--> 254 dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
255
256 remainder = float(x) - ix
ValueError: ordinal must be >= 1
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
330 pass
331 else:
--> 332 return printer(obj)
333 # Finally look for special method names
334 method = get_real_method(obj, self.print_method)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
235
236 if 'png' in formats:
--> 237 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
238 if 'retina' in formats or 'png2x' in formats:
239 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
119
120 bytes_io = BytesIO()
--> 121 fig.canvas.print_figure(bytes_io, **kw)
122 data = bytes_io.getvalue()
123 if fmt == 'svg':
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2198 orientation=orientation,
2199 dryrun=True,
-> 2200 **kwargs)
2201 renderer = self.figure._cachedRenderer
2202 bbox_inches = self.figure.get_tightbbox(renderer)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
543
544 def print_png(self, filename_or_obj, *args, **kwargs):
--> 545 FigureCanvasAgg.draw(self)
546 renderer = self.get_renderer()
547 original_dpi = renderer.dpi
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
462
463 try:
--> 464 self.figure.draw(self.renderer)
465 finally:
466 RendererAgg.lock.release()
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/figure.py in draw(self, renderer)
1142
1143 mimage._draw_list_compositing_images(
-> 1144 renderer, self, dsu, self.suppressComposite)
1145
1146 renderer.close_group('figure')
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2424 renderer.stop_rasterizing()
2425
-> 2426 mimage._draw_list_compositing_images(renderer, self, dsu)
2427
2428 renderer.close_group('axes')
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)
1134 renderer.open_group(__name__)
1135
-> 1136 ticks_to_draw = self._update_ticks(renderer)
1137 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
1138 renderer)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in _update_ticks(self, renderer)
967
968 interval = self.get_view_interval()
--> 969 tick_tups = [t for t in self.iter_ticks()]
970 if self._smart_bounds:
971 # handle inverted limits
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in <listcomp>(.0)
967
968 interval = self.get_view_interval()
--> 969 tick_tups = [t for t in self.iter_ticks()]
970 if self._smart_bounds:
971 # handle inverted limits
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in iter_ticks(self)
910 Iterate through all of the major and minor ticks.
911 """
--> 912 majorLocs = self.major.locator()
913 majorTicks = self.get_major_ticks(len(majorLocs))
914 self.major.formatter.set_locs(majorLocs)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in __call__(self)
984 def __call__(self):
985 'Return the locations of the ticks'
--> 986 self.refresh()
987 return self._locator()
988
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in refresh(self)
1004 def refresh(self):
1005 'Refresh internal information based on current limits.'
-> 1006 dmin, dmax = self.viewlim_to_dt()
1007 self._locator = self.get_locator(dmin, dmax)
1008
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in viewlim_to_dt(self)
761 vmin, vmax = vmax, vmin
762
--> 763 return num2date(vmin, self.tz), num2date(vmax, self.tz)
764
765 def _get_unit(self):
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in num2date(x, tz)
399 tz = _get_rc_timezone()
400 if not cbook.iterable(x):
--> 401 return _from_ordinalf(x, tz)
402 else:
403 x = np.asarray(x)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in _from_ordinalf(x, tz)
252
253 ix = int(x)
--> 254 dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
255
256 remainder = float(x) - ix
ValueError: ordinal must be >= 1
<matplotlib.figure.Figure at 0x118f1e978>
You probably want to plot column 1 agains column 0, i.e. the numbers against the dates? This would be done via
df.plot(x=0,y=1)
Your columns are unnamed. So you may also name them and reset the index to something useful (or as below, not so useful ;-))
df.columns = ["0", "1"]
df = df.set_index("0")
df.plot()
Both should give you a plot like the following:
I want use red and green to distinguish positive and negative num which will be used abs(num) in one picture. I search on web and find some method to deal with it. but the result is error. I paste the code and wish sb. to help.
"df_combine" file like this:
t o h l c nu octime ocsize cum_size
0 2017-07-02 22:01:00 1241.65 1241.85 1241.63 1241.85 0 2017-07-02 22:01:32 32 32
1 2017-07-02 22:02:00 1241.95 1241.95 1241.85 1241.95 0 2017-07-02 22:02:00 -24 12
2 2017-07-02 22:03:00 1242.05 1242.15 1242.05 1242.15 0 2017-07-02 22:03:00 -48 -36
3 2017-07-02 22:04:00 1242.25 1242.25 1242.16 1242.17 0 2017-07-02 22:04:00 -100 -136
4 2017-07-02 22:05:00 1242.16 1242.57 1241.85 1242.57 0 2017-07-02 22:05:00 200 64
holding_info file like this:
cum_size factor
0 32.0 True
1 12.0 True
2 -36.0 False
3 -136.0 False
4 64.0 True
code like this:
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
t=df_combine.iloc[:,0]
o=df_combine.iloc[:,1]
h=df_combine.iloc[:,2]
l=df_combine.iloc[:,3]
c=df_combine.iloc[:,4]
holding_octime=df_combine['t']
holding_size=df_combine['cum_size'] ##df_cumbine is a DataFrame
holding_info=pd.Series.to_frame(holding_size)
holding_info['factor']=holding_info['cum_size']>0
fig,ax1=plt.subplots()
ax1.plot_date(t,o,linestyle='--',color='b',marker='D',alpha=0.6) ##t,o,h,l,c are pd.Series which contains time and price
ax1.plot_date(t,c,linestyle='--',color='k',marker='D',alpha=0.6)
ax1.plot_date(t,h,color='g',marker='^',alpha=0.3)
ax1.plot_date(t,l,color='r',marker='v',alpha=0.3)
ax2=ax1.twinx()
ax2.plot_date(holding_octime,abs(holding_size),color=holding_info.factor.map({True:'r', False:'k'})) ##octime is a pd.Series which contains time
dformat=mpl.dates.DateFormatter('%Y.%m.%d %H:%M')
ax1.xaxis.set_major_formatter(dformat)
fig.autofmt_xdate()
plt.show()
find error like this:
> ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
305 pass
306 else:
--> 307 return printer(obj)
308 # Finally look for special method names
309 method = get_real_method(obj, self.print_method)
C:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
238
239 if 'png' in formats:
--> 240 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
241 if 'retina' in formats or 'png2x' in formats:
242 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
C:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
122
123 bytes_io = BytesIO()
--> 124 fig.canvas.print_figure(bytes_io, **kw)
125 data = bytes_io.getvalue()
126 if fmt == 'svg':
C:\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2198 orientation=orientation,
2199 dryrun=True,
-> 2200 **kwargs)
2201 renderer = self.figure._cachedRenderer
2202 bbox_inches = self.figure.get_tightbbox(renderer)
C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
543
544 def print_png(self, filename_or_obj, *args, **kwargs):
--> 545 FigureCanvasAgg.draw(self)
546 renderer = self.get_renderer()
547 original_dpi = renderer.dpi
C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
462
463 try:
--> 464 self.figure.draw(self.renderer)
465 finally:
466 RendererAgg.lock.release()
C:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
C:\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1142
1143 mimage._draw_list_compositing_images(
-> 1144 renderer, self, dsu, self.suppressComposite)
1145
1146 renderer.close_group('figure')
C:\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
C:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
C:\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2424 renderer.stop_rasterizing()
2425
-> 2426 mimage._draw_list_compositing_images(renderer, self, dsu)
2427
2428 renderer.close_group('axes')
C:\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
C:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
C:\Anaconda3\lib\site-packages\matplotlib\lines.py in draw(self, renderer)
826 gc = renderer.new_gc()
827 self._set_gc_clip(gc)
--> 828 rgbaFace = self._get_rgba_face()
829 rgbaFaceAlt = self._get_rgba_face(alt=True)
830 edgecolor = self.get_markeredgecolor()
C:\Anaconda3\lib\site-packages\matplotlib\lines.py in _get_rgba_face(self, alt)
1335 def _get_rgba_face(self, alt=False):
1336 facecolor = self._get_markerfacecolor(alt=alt)
-> 1337 if is_string_like(facecolor) and facecolor.lower() == 'none':
1338 rgbaFace = None
1339 else:
C:\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
2968 if name in self._info_axis:
2969 return self[name]
-> 2970 return object.__getattribute__(self, name)
2971
2972 def __setattr__(self, name, value):
AttributeError: 'Series' object has no attribute 'lower'
<matplotlib.figure.Figure at 0x9db80b8>
i study the code from another case like this. if I use ax1.plot instead of ax1.plot_date, then the error information change to :
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
C:\Anaconda3\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)
140 try:
--> 141 rgba = _colors_full_map.cache[c, alpha]
142 except (KeyError, TypeError): # Not in cache, or unhashable.
C:\Anaconda3\lib\site-packages\pandas\core\generic.py in __hash__(self)
830 raise TypeError('{0!r} objects are mutable, thus they cannot be'
--> 831 ' hashed'.format(self.__class__.__name__))
832
TypeError: 'Series' objects are mutable, thus they cannot be hashed
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
C:\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
305 pass
306 else:
--> 307 return printer(obj)
308 # Finally look for special method names
309 method = get_real_method(obj, self.print_method)
C:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
225
226 if 'png' in formats:
--> 227 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
228 if 'retina' in formats or 'png2x' in formats:
229 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
C:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
117
118 bytes_io = BytesIO()
--> 119 fig.canvas.print_figure(bytes_io, **kw)
120 data = bytes_io.getvalue()
121 if fmt == 'svg':
C:\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2190 orientation=orientation,
2191 dryrun=True,
-> 2192 **kwargs)
2193 renderer = self.figure._cachedRenderer
2194 bbox_inches = self.figure.get_tightbbox(renderer)
C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
543
544 def print_png(self, filename_or_obj, *args, **kwargs):
--> 545 FigureCanvasAgg.draw(self)
546 renderer = self.get_renderer()
547 original_dpi = renderer.dpi
C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
462
463 try:
--> 464 self.figure.draw(self.renderer)
465 finally:
466 RendererAgg.lock.release()
C:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist,
renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
C:\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1141
1142 mimage._draw_list_compositing_images(
-> 1143 renderer, self, dsu, self.suppressComposite)
1144
1145 renderer.close_group('figure')
C:\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
C:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
C:\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2407 renderer.stop_rasterizing()
2408
-> 2409 mimage._draw_list_compositing_images(renderer, self, dsu)
2410
2411 renderer.close_group('axes')
C:\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
C:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
C:\Anaconda3\lib\site-packages\matplotlib\lines.py in draw(self, renderer)
801 self._set_gc_clip(gc)
802
--> 803 ln_color_rgba = self._get_rgba_ln_color()
804 gc.set_foreground(ln_color_rgba, isRGBA=True)
805 gc.set_alpha(ln_color_rgba[3])
C:\Anaconda3\lib\site-packages\matplotlib\lines.py in _get_rgba_ln_color(self, alt)
1342
1343 def _get_rgba_ln_color(self, alt=False):
-> 1344 return mcolors.to_rgba(self._color, self._alpha)
1345
1346 # some aliases....
C:\Anaconda3\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)
141 rgba = _colors_full_map.cache[c, alpha]
142 except (KeyError, TypeError): # Not in cache, or unhashable.
--> 143 rgba = _to_rgba_no_colorcycle(c, alpha)
144 try:
145 _colors_full_map.cache[c, alpha] = rgba
C:\Anaconda3\lib\site-packages\matplotlib\colors.py in _to_rgba_no_colorcycle(c, alpha)
190 # not numpy floats.
191 try:
--> 192 c = tuple(map(float, c))
193 except TypeError:
194 raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: could not convert string to float: 'k'
<matplotlib.figure.Figure at 0x263096fa128>
why this happen?
and what i really what to do is make a bar chart of cumsum size and plot price in the same image
or
if size>n(linspace maybe 50,100,200),make the whole background which in several time range in different colors. like between 2017-8-19 08:20:10 and 2017-8-19 08:30:20,size=70,then use yellow to fill this range background.and between 2017-8-20 08:20:10 and 2017-8-20 08:30:20,size=150,then use red to fill this range background.
just solve one problem is good, some idea can not figure out in one time:)