File:Weighted median.svg
From testwiki
Jump to navigation
Jump to search
Original file (SVG file, nominally 383 × 515 pixels, file size: 24 KB)
Contents
This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.
Summary
| DescriptionWeighted median.svg |
English: Two charts showing the difference between an ordinary median and a weighted median. The weight of the element in the list is are indicated by the widths of the boxes and the value by height. The median element is shown in red. |
| Date | |
| Source | Own work |
| Author | Bscan |
| SVG development InfoField |
Source code

This media was created with Matplotlib (comprehensive library for creating static, animated, and interactive visualizations in Python)
Here is a listing of the source used to create this file.
Here is a listing of the source used to create this file.
Deutsch ∙ македонски ∙ English ∙ +/−
#Python code shown below
#This code is issued under the Creative Commons CC0 "License"
from pylab import *
#Arbitrary values that result in a good illustrative example
data = array([1,3,4,5,8,8.5,9,10.5,11])
weights = array([0.24, 0.60, 0.33,0.28, 0.2, 0.39, 0.2, 0.1, 0.18])
bar_spacing = 0.02 #Distance between adjacent bars
#Non-medians are blue and the median is red
colors = ['b','b','b','b','r','b','b','b','b']
colorsw = ['b','b','b','r','b','b','b','b','b']
#normalize the weights, only needed to get the two plots to line up
weights = weights / sum(weights)
unweights = ones(data.__len__())/data.__len__() #Equal weighting
#The locations start at zero and are spaced by the width
locations = concatenate((array([0]),cumsum(bar_spacing + unweights[:-1])))
locations_w = concatenate((array([0]),cumsum(bar_spacing + weights[:-1])))
figure()
subplot(2,1,1)
bar(locations, data, width=unweights, color = colors)
ylabel('Value')
tick_params(axis='x', which='both',bottom='off',top='off',labelbottom='off')
xlim([-0.02, sum(unweights+0.02)])
grid()
xticks([])
subplot(2,1,2)
bar(locations_w, data, width=weights, color = colorsw)
ylabel('Value')
tick_params(axis='x', which='both',bottom='off',top='off',labelbottom='off')
xlim([-0.02, sum(weights+0.02)])
grid()
xticks([])
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
| This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. | |
| The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse |
Captions
Add a one-line explanation of what this file represents
Items portrayed in this file
depicts
2 December 2013
24,598 byte
image/svg+xml
960ad4e316d8d602f18d55804c9a4ed1b87252ef
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 03:33, 3 December 2013 | 383 × 515 (24 KB) | wikimediacommons>Bscan | Minor updates: changed data slightly to make different median more apparent and added grid lines |
File usage
There are no pages that use this file.
Retrieved from "https://en.wiki.beta.math.wmcloud.org/wiki/File:Weighted_median.svg"