## 准备数据 modified_file_path = './data/cleaned_with_spectral_class.csv' data = pd.read_csv(modified_file_path) data_to_draw = { 'A': [], 'F': [], 'G': [], 'K': [] } combined_teff_index = data.columns.tolist().index('combined_teff') combined_logg_index = data.columns.tolist().index('combined_logg') spectral_class_index = data.columns.tolist().index('spectral_class') for row in data.iterrows(): teff_logg = [row[1][combined_teff_index], row[1][combined_logg_index]] data_to_draw[row[1][spectral_class_index]].append(teff_logg) ## echarts代码 var dom = document.getElementById('chart-container'); var myChart = echarts.init(dom, 'dark', { renderer: 'canvas', useDirtyRect: false }); var app = {}; var option; // 可以在jupyter notebook打印出来之后(如print(data_to_draw['A])等)直接复制过来 const A = ... const F = ... const G = ... const K = ... const scatterOption = (option = { title: { text: '赫罗图', subtext: 'Data from: LAMOST DR7 v2.0低分辨率数据(2021-06-12)' }, xAxis: { scale: true, name: '有效温度 (Teff)', nameLocation: 'center', inverse: true }, yAxis: { scale: true, name: '表面重力 (logg)', nameLocation: 'center' }, series: [ { type: 'scatter', id: 'A', dataGroupId: 'A', universalTransition: { enabled: true, delay: function (idx, count) { return Math.random() * 400; } }, data: A }, { type: 'scatter', id: 'F', dataGroupId: 'F', universalTransition: { enabled: true, delay: function (idx, count) { return Math.random() * 400; } }, data: F }, { type: 'scatter', id: 'G', dataGroupId: 'G', universalTransition: { enabled: true, delay: function (idx, count) { return Math.random() * 400; } }, data: G }, { type: 'scatter', id: 'K', dataGroupId: 'K', universalTransition: { enabled: true, delay: function (idx, count) { return Math.random() * 400; } }, data: K } ] }); const barOption = { title: { text: '数量统计图', subtext: 'Data from: LAMOST DR7 v2.0低分辨率数据(2021-06-12)' }, xAxis: { type: 'category', data: ['A', 'F', 'G', 'K'], name: '恒星子类型', nameLocation: 'center' }, yAxis: {}, series: [ { type: 'bar', id: 'total', data: [ { value: A.length, groupId: 'A' }, { value: F.length, groupId: 'F' }, { value: G.length, groupId: 'G' }, { value: K.length, groupId: 'K' } ], universalTransition: { enabled: true, seriesKey: ['A', 'F', 'G', 'K'], delay: function (idx, count) { return Math.random() * 400; } } } ] }; let currentOption = scatterOption; setInterval(function () { currentOption = currentOption === scatterOption ? barOption : scatterOption; myChart.setOption(currentOption, true); }, 2000); if (option && typeof option === 'object') { myChart.setOption(option); } window.addEventListener('resize', myChart.resize);