Eroare valoare atunci când Trasarea o histogramă 2D cu Matplotlib

voturi
0

Am încercat să complot o histogramă 2D cu Matplotlib folosind următorul cod:

import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import csv

lum = []
bprp = []

with open('combined.csv', 'r') as f:
    table = csv.reader(f)

    firstLine = True

    for row in table:
        if firstLine:
            firstLine = False
            continue
        try:
            parallax = float(row[9])
            magnitude = float(row[50])
            luminosity = (10 * parallax)**(-2) * 10**(0.4 * (4.83 - magnitude))
            lum.append(luminosity)
            bprp.append(float(row[55])-float(row[60]))           

        except:
            pass

print(Number of stars: , len(lum))

plt.hist2d(bprp, lum, bins=1000, norm=LogNorm(), cmap=plasma)

plt.ylabel(r$log_{10}[ Lumonisity (L_\odot) ]$)
plt.xlabel(Mean BP Mag - Mean RP Mag (mag))

#plt.xscale(log)
plt.colorbar()
#plt.ylim(-4,10)
#plt.xlim(-1,5)
#plt.gca().invert_yaxis()

plt.savefig(hertzprung_russell_alldata_colour_hist3.png)
plt.show()

Dar când l-am alerga, se plânge cu eroarea:

Number of stars:  1526347
Traceback (most recent call last):
  File C:/Users/Tachyon/Documents/programming/gaia/hertzprung_russell_colour2.py, line 31, in <module>
    plt.hist2d(bprp, lum, bins=1000, norm=LogNorm(), cmap=plasma)
  File C:\Users\Tachyon\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\pyplot.py, line 3106, in hist2d
    **kwargs)
  File C:\Users\Tachyon\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\__init__.py, line 1892, in inner
    return func(ax, *args, **kwargs)
  File C:\Users\Tachyon\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\axes\_axes.py, line 6479, in hist2d
    normed=normed, weights=weights)
  File C:\Users\Tachyon\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\lib\twodim_base.py, line 649, in histogram2d
    hist, edges = histogramdd([x, y], bins, range, normed, weights)
  File C:\Users\Tachyon\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\lib\function_base.py, line 908, in histogramdd
    smin = atleast_1d(array(sample.min(0), float))
ValueError: setting an array element with a sequence.

Se pare că această eroare este o eroare cu NumPy, mai degrabă decât cu matplotlib, astfel încât există nici un fel în jurul acestei? A lucrat înainte, fără calculele de luminozitate.

Întrebat 18/05/2018 la 15:19
sursa de către utilizator
În alte limbi...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more