'How to plot color code with 3 axes of random data using matplotlib?
I want to get color coding plot. I have a dataset of 32000 rows and 3 axes. I am sharing the code and error. Also I will upload the result I want. Please help me get this.
Code:-
import numpy as np
import matplotlib.pyplot as plt
from astropy.table import QTable, Table, Column
%matplotlib inline
t = Table.read("grid_extinc_15arcmin.dat", format="ascii")
x = t['x']
y = t['y']
Av = t['Av']
print(x)
#fig = plt.figure(figsize=(5,3.5))
#ax = fig.add_subplot(111,projection='3d')
#ax.scatter(x, y, Av)
color = [Av]
plt.scatter(x,y, s=200, z=color,marker=".", cmap="bwr_r")
#ax = plt.subplot(111)
#ax.imshow(x, y, Av, norm='none', origin='lower')
#ax.pcolormesh(x, y, Av)
plt.colorbar()
And the Error I got:-
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_8648/2430433142.py in <module>
22 #print(color)
23
---> 24 plt.scatter(x,y, s=200, z=color,marker=".", cmap="bwr_r")
25 #plt.scatter(y,Av, s=200, marker=".", cmap="bwr_r")
26 #plt.set_cmap('inferno_r')
E:\Users\SOUMITA\anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, plotnonfinite, data, **kwargs)
3066 vmin=None, vmax=None, alpha=None, linewidths=None, *,
3067 edgecolors=None, plotnonfinite=False, data=None, **kwargs):
-> 3068 __ret = gca().scatter(
3069 x, y, s=s, c=c, marker=marker, cmap=cmap, norm=norm,
3070 vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths,
E:\Users\SOUMITA\anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
1359 def inner(ax, *args, data=None, **kwargs):
1360 if data is None:
-> 1361 return func(ax, *map(sanitize_sequence, args), **kwargs)
1362
1363 bound = new_sig.bind(ax, *args, **kwargs)
E:\Users\SOUMITA\anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, plotnonfinite, **kwargs)
4595 )
4596 collection.set_transform(mtransforms.IdentityTransform())
-> 4597 collection.update(kwargs)
4598
4599 if colors is None:
E:\Users\SOUMITA\anaconda3\lib\site-packages\matplotlib\artist.py in update(self, props)
1060 func = getattr(self, f"set_{k}", None)
1061 if not callable(func):
-> 1062 raise AttributeError(f"{type(self).__name__!r} object "
1063 f"has no property {k!r}")
1064 ret.append(func(v))
AttributeError: 'PathCollection' object has no property 'z'
Also I am attaching the output I want to get... This is the result I want
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
