php動態(tài)網(wǎng)站開發(fā)第四章企業(yè)seo關(guān)鍵詞優(yōu)化
柱狀圖的高級平替可視化
“玫瑰圖”,通常也被稱為“科克斯圖”。它類似于餅圖,但不同之處在于每個部分(或“花瓣”)的角度相同,半徑根據(jù)它表示的值而變化。這種可視化工具對于周期性地顯示信息非常有用,比如一年中每月的數(shù)據(jù),就像您的圖表一樣,每個“花瓣”對應(yīng)一個月份。花瓣的長度代表該月的數(shù)值,讓觀看者能夠快速看出哪些月份的值相對較高或較低。這種圖表曾被佛羅倫薩·南丁格爾用來說明克里米亞戰(zhàn)爭期間的死亡原因。
?優(yōu)點
1. 直觀展示時間序列數(shù)據(jù):非常適合展示隨時間變化的數(shù)據(jù),如月度或年度的比較。
2. 突出顯示數(shù)據(jù)模式:因其獨特的設(shè)計,可以突出顯示數(shù)據(jù)中的模式和趨勢。
3. 視覺吸引力:具有高度的視覺吸引力,可以吸引觀眾的注意力。
4. 展示多個變量:能夠在一個圖表中同時展示多個變量,有助于比較和對比。
5. 歷史意義:作為一種歷史悠久的數(shù)據(jù)可視化方法,它在某些情境中具有教育和傳統(tǒng)上的價值。
?缺點
1. 解讀困難:對于不熟悉這種圖表的觀眾來說,可能難以理解和解讀。
2. 誤導(dǎo)風(fēng)險:由于區(qū)域的大小可能會造成誤解,尤其是當(dāng)外圈的變量值較大時,可能會被過分強調(diào)。
3. 不適合復(fù)雜數(shù)據(jù):對于包含許多類別或復(fù)雜數(shù)據(jù)的情況,可能不是最佳選擇。
4. 比較困難:如果需要精確比較數(shù)據(jù)點的大小,這種圖表可能不太合適,因為人眼不擅長比較環(huán)形區(qū)域的面積。
5. 受限的數(shù)據(jù)量:不適合展示大量的數(shù)據(jù)點,因為圖表會變得擁擠且難以閱讀。
比如下圖,我隨即生成了一組數(shù)據(jù)集每個月份具有一個數(shù)值,如下的柱狀圖,為了更加直觀的展示其結(jié)果,就可以繪制玫瑰圖如下所示。
import matplotlib.pyplot as plt
import numpy as np# Generate random data for 12 months
data = np.random.rand(12) * 100# Define the angle of each sector
theta = np.linspace(0.0, 2 * np.pi, 12, endpoint=False)# Sort the data from smallest to largest
sorted_data = np.sort(data)# Create the plot with the sorted data
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})# Create the bars of the rose chart with sorted data
bars = ax.bar(theta, sorted_data, width=0.5, bottom=0.0, color=plt.cm.viridis(sorted_data / 100))# Set the labels for each 'petal'
ax.set_xticks(theta)
ax.set_xticklabels(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])# Remove the yticks
ax.set_yticks([])# Add the data values on top of each bar
for bar, value in zip(bars, sorted_data):ax.text(bar.get_x() + bar.get_width()/2, bar.get_height(), f'{value:.1f}',ha='center', va='bottom')# Show the plot
plt.show()
為了進一步美化我們使用了漸變的顏色條,加粗了月份標(biāo)簽,并在每個花瓣上方以加粗字體標(biāo)注了數(shù)據(jù)值。此外,還調(diào)整了背景顏色,網(wǎng)格線樣式,以及去除了極坐標(biāo)的邊框,使整個圖表看起來更加清晰和現(xiàn)代。?
?
也可以直接使用SPSSPRO的PRO繪圖功能繪制。如下所示?
還為大家準(zhǔn)備了matlab繪制代碼?
% Random data for 12 months
data = rand(1, 12) * 100;% Define the angle of each sector
theta = linspace(0, 2 * pi, 13);
theta(end) = []; % To make it 12 elements only% Sort the data and associated labels
[sorted_data, sortIndex] = sort(data);
sorted_labels = {'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'};
sorted_labels = sorted_labels(sortIndex);% Create a polar plot
figure('Color', 'white');
pax = polaraxes;
hold on;% Set the colormap
colors = colormap(hot(12));% Create the bars
bars = polarplot([theta; theta], [zeros(1, numel(sorted_data)); sorted_data], 'LineWidth', 10);
for i = 1:length(bars)bars(i).Color = colors(i, :);
end% Set the labels for each 'petal'
pax.ThetaTick = rad2deg(theta);
pax.ThetaTickLabel = sorted_labels;% Add the data values on top of each bar
for i = 1:length(sorted_data)text(theta(i), sorted_data(i) + max(data)*0.05, sprintf('%.1f', sorted_data(i)), ...'HorizontalAlignment', 'center', 'FontWeight', 'bold', 'Color', [0 0 0.5]);
end% Customize polar grid and frame
pax.GridLineStyle = '--';
pax.GridColor = [0.5, 0.5, 0.5];
pax.GridAlpha = 0.5;% Hide the polar frame/spine
pax.RAxis.Visible = 'off';% Add a title
title('Monthly Data Rose Chart', 'FontSize', 16, 'FontWeight', 'bold', 'Color', [0 0 0.5]);% Show the plot
hold off;
?同時,為了進一步美化可視化結(jié)果我們增加標(biāo)簽和圖例、添加數(shù)據(jù)的百分比或數(shù)值標(biāo)簽、改進極坐標(biāo)網(wǎng)格線等操作,最終可視化結(jié)果如下所示
?