Themes

Many parameters controlling the appearance of plots can be overridden by passing a Theme object to the plot function, or setting the Theme as the current theme using push_theme or with_theme.

The constructor for Theme takes zero or more keyword arguments each of which overrides the default value of the corresponding field. See Theme for a full list of keywords.

using Gadfly, RDatasets
mammals = dataset("MASS", "mammals")
plot(mammals, x=:Body, y=:Brain, label=:Mammal,
     Geom.point, Geom.label, Scale.x_log10, Scale.y_log10,
     Theme(discrete_highlight_color=x->"red", default_color="white"))
Body 10-14 10-12 10-10 10-8 10-6 10-4 10-2 100 102 104 106 108 1010 1012 1014 10-12.0 10-11.5 10-11.0 10-10.5 10-10.0 10-9.5 10-9.0 10-8.5 10-8.0 10-7.5 10-7.0 10-6.5 10-6.0 10-5.5 10-5.0 10-4.5 10-4.0 10-3.5 10-3.0 10-2.5 10-2.0 10-1.5 10-1.0 10-0.5 100.0 100.5 101.0 101.5 102.0 102.5 103.0 103.5 104.0 104.5 105.0 105.5 106.0 106.5 107.0 107.5 108.0 108.5 109.0 109.5 1010.0 1010.5 1011.0 1011.5 1012.0 10-20 10-10 100 1010 1020 10-12.0 10-11.5 10-11.0 10-10.5 10-10.0 10-9.5 10-9.0 10-8.5 10-8.0 10-7.5 10-7.0 10-6.5 10-6.0 10-5.5 10-5.0 10-4.5 10-4.0 10-3.5 10-3.0 10-2.5 10-2.0 10-1.5 10-1.0 10-0.5 100.0 100.5 101.0 101.5 102.0 102.5 103.0 103.5 104.0 104.5 105.0 105.5 106.0 106.5 107.0 107.5 108.0 108.5 109.0 109.5 1010.0 1010.5 1011.0 1011.5 1012.0 Arctic fox Owl monkey Mountain beaver Cow Grey wolf Goat Roe deer Guinea pig Verbet Chinchilla Ground squirrel Arctic ground squirrel African giant pouched rat Lesser short-tailed shrew Star-nosed mole Nine-banded armadillo Tree hyrax N.A. opossum Asian elephant Big brown bat Donkey Horse European hedgehog Patas monkey Cat Galago Genet Giraffe Gorilla Grey seal Rock hyrax-a Human African elephant Water opossum Rhesus monkey Kangaroo Yellow-bellied marmot Golden hamster Mouse Little brown bat Slow loris Okapi Rabbit Sheep Jaguar Chimpanzee Baboon Desert hedgehog Giant armadillo Rock hyrax-b Raccoon Rat E. American mole Mole rat Musk shrew Pig Echidna Brazilian tapir Tenrec Phalanger Tree shrew Red fox 0.62685341466672571.7024305364455252 -0.98296666070121960.3979400086720376 0.209515014542630971.0569048513364727 -0.0457574905606751150.414973347970818 2.20411998265592462.2278867046136734 0.477121254719662441.3979400086720377 2.28330122870354972.255272505103306 -1.3187587626244128-0.4814860601221125 -0.91364016932525180.47712125471966244 -1.12493873660830.07918124604762482 -0.55284196865778080.2787536009528289 0.63225477668471361.5932860670204574 0.55630250076728731.3222192947339193 1.77815125038364361.9084850188786497 -0.25963731050575610.38021124171160603 1.02325245963371162.254064452914338 1.71733758272386372.6434526764861874 2.02.1958996524092336 1.74429298312267632.2430380486862944 0.39794000867203761.08278537031645 2.39794000867203752.690196080028514 0.1461280356782381.0969100130080565 -2.0-0.6020599913279624 -1.6382721639824072-0.3979400086720376 -0.92081875395237520.0 0.60745502321466851.2304489213782739 1.54406804435027571.7481880270062005 0.83250891270623632.2528530309798933 0.54406804435027570.5910646070264992 3.82308279653280363.7567881987681178 1.7923916894982543.12057393120585 -0.124938736608299951.089905111439398 1.92941892571429262.5118833609788744 2.3159703454569182.6085260335771943 2.72345567203518572.832508912706236 0.149219112655379881.2430380486862944 -0.69897000433601870.6989700043360189 0.51851393987788741.4082399653118496 1.02.060697840353612 -0.105130343254747450.5440680443502757 2.71683772329952472.816241299991783 2.272073787500012.622214022966295 -1.6382721639824072-0.5228787452803376 3.4060289449636153.663040974893974 0.23044892137827390.7993405494535817 0.30102999566398121.089905111439398 0.54406804435027571.0334237554869496 -1.22184874961635640.0 -2.3010299956639813-0.8538719643217619 0.00.8195439355418687 -0.0362121726544447150.7558748556724915 -0.99567862621735740.6020599913279624 -0.371611069949688460.8061799739838872 0.62221402296629541.7634279935629373 0.017033339298780370.7403626894942439 1.1711411510283821.9921114877869497 1.44185217577329182.060697840353612 1.56026539786271462.0773679052841563 2.6674529528899542.6263403673750423 0.130333768495006140.9084850188786497 -0.31875876262441281.1903316981702914 0.52955867302116311.6483600109809315 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? 10-7 10-6 10-5 10-4 10-3 10-2 10-1 100 101 102 103 104 105 106 107 108 109 1010 10-6.0 10-5.5 10-5.0 10-4.5 10-4.0 10-3.5 10-3.0 10-2.5 10-2.0 10-1.5 10-1.0 10-0.5 100.0 100.5 101.0 101.5 102.0 102.5 103.0 103.5 104.0 104.5 105.0 105.5 106.0 106.5 107.0 107.5 108.0 108.5 109.0 10-10 10-5 100 105 1010 10-6.0 10-5.8 10-5.6 10-5.4 10-5.2 10-5.0 10-4.8 10-4.6 10-4.4 10-4.2 10-4.0 10-3.8 10-3.6 10-3.4 10-3.2 10-3.0 10-2.8 10-2.6 10-2.4 10-2.2 10-2.0 10-1.8 10-1.6 10-1.4 10-1.2 10-1.0 10-0.8 10-0.6 10-0.4 10-0.2 100.0 100.2 100.4 100.6 100.8 101.0 101.2 101.4 101.6 101.8 102.0 102.2 102.4 102.6 102.8 103.0 103.2 103.4 103.6 103.8 104.0 104.2 104.4 104.6 104.8 105.0 105.2 105.4 105.6 105.8 106.0 106.2 106.4 106.6 106.8 107.0 107.2 107.4 107.6 107.8 108.0 108.2 108.4 108.6 108.8 109.0 Brain

The Theme stack

Gadfly maintains a stack of themes and applies theme values from the topmost theme in the stack. This can be useful when you want to set a theme for multiple plots and then switch back to a previous theme.

push_theme(t::Theme) and pop_theme() will push and pop from this stack respectively. You can also use with_theme(f, t::Theme) to temporarily set a theme as the current theme and call function f, which can be defined elsewhere, anonymously, or as a do-block.

For example, here is how to choose a different font:

latex_fonts = Theme(major_label_font="CMU Serif", major_label_font_size=16pt,
                    minor_label_font="CMU Serif", minor_label_font_size=14pt,
                    key_title_font="CMU Serif", key_title_font_size=12pt,
                    key_label_font="CMU Serif", key_label_font_size=10pt)
Gadfly.push_theme(latex_fonts)
gasoline = dataset("Ecdat", "Gasoline")
p = plot(gasoline, x=:Year, y=:LGasPCar, color=:Country, Geom.point, Geom.line)
# can plot more plots here...
Gadfly.pop_theme()
Year 1935 1940 1945 1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000 2005 1940 1942 1944 1946 1948 1950 1952 1954 1956 1958 1960 1962 1964 1966 1968 1970 1972 1974 1976 1978 1980 1982 1984 1986 1988 1990 1992 1994 1996 1998 2000 1940 1960 1980 2000 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 JAPAN NETHERLA NORWAY SPAIN SWEDEN SWITZERL TURKEY U.K. U.S.A. AUSTRIA BELGIUM CANADA DENMARK FRANCE GERMANY GREECE IRELAND ITALY Country 19784.8184539683 19774.811032467 19764.8148907167 19754.8049322352 19744.7986259444 19734.8463745073 19724.8540732646 19714.8602864749 19704.8484842122 19694.841382713 19684.8341417653 19674.8008834761 19664.8075305603 19654.8059545113 19644.8082735727 19634.7878951522 19624.7989365652 19614.7963170698 19604.8239645123 19784.0003742149 19773.945553345 19763.962305336 19753.9125838579 19743.966961453 19733.995364122 19723.992756786 19713.9836534009 19703.9797051949 19693.948058368 19683.9532027179 19673.9436308491 19663.957212164 19653.968675694 19643.976781186 19633.9852710359 19624.0480509119 19614.0886358 19604.1002442839 19785.1412554768 19775.313462422 19765.312929193 19755.4267771741 19745.42772844 19735.68647036 19725.5788213319 19715.6696463189 19705.72210507 19695.7207051419 19686.0765946269 19676.044478582 19666.156644407 19655.8230458949 19646.064600869 19636.0751291349 19626.0845870211 19616.106212679 19606.1295528491 19784.050047696 19774.100533339 19764.0795721801 19754.120567757 19744.166363739 19734.2298161621 19724.2591593359 19714.280697003 19704.22529671 19694.211290089 19684.2177878429 19674.265918883 19664.2663516041 19654.288713915 19644.3134274369 19634.312484529 19624.2871473959 19614.441329648 19604.397621493 19784.067373445 19774.0310109309 19763.983996505 19753.9738404359 19743.913159154 19734.0305604061 19723.9800657581 19713.982061858 19703.989372472 19693.9917150449 19683.997584757 19673.9973460479 19664.0025573741 19654.015463106 19644.024858515 19634.00276563 19624.0064390159 19614.061869959 19604.063010036 19783.6204438709 19773.6507346971 19763.7108746111 19753.7524488659 19743.768565146 19733.912811545 19723.8912244911 19713.9073442129 19703.96604596 19693.9941031169 19684.0442530621 19674.086322459 19664.113780911 19654.217208979 19644.300577007 19634.346497214 19624.429087629 19614.589239364 19604.7494091723 19784.0024867129 19773.988515537 19763.978209728 19753.9960249669 19743.9603309711 19734.0613489569 19724.077257431 19714.078931746 19704.0888057159 19694.0868228049 19684.103864323 19674.0643140609 19664.0846073869 19654.131633441 19644.164351876 19634.216189342 19624.2342411029 19614.33271925 19604.43504067 19783.8825941949 19773.7766816581 19763.7836345681 19753.718466264 19743.7113837231 19733.8804785129 19723.915296331 19713.9478037431 19703.956407876 19693.987689339 19684.0707346969 19674.119154995 19664.168016513 19654.233001576 19644.31956339 19634.377686978 19624.471717068 19614.559839938 19604.6462680045 19783.9487463871 19773.9646719111 19763.9881620001 19753.995984493 19744.007963901 19734.0938837331 19724.2229757 19714.305623621 19704.401596952 19694.518289907 19684.6846663526 19674.8548612373 19665.0008214407 19655.125850803 19645.275327848 19635.5080817012 19625.6419150489 19615.7584836101 19605.9952865559 19783.3945044428 19773.3802089569 19763.4276288189 19753.5156795149 19743.4994699 19733.6522633939 19723.629243426 19713.6482050719 19703.706871673 19693.737389284 19683.7639029799 19673.7858083619 19663.8227352401 19653.8749851811 19643.936324254 19633.963086271 19624.0289989679 19614.0452481041 19604.050728238 19784.198610729 19774.2415507701 19764.2211462271 19754.248218349 19744.3255853241 19734.253827008 19724.270767878 19714.267117754 19704.2499445181 19694.208612656 19684.18111984 19674.188989564 19664.1682144109 19654.164895673 19644.186242773 19634.176695597 19624.2084346371 19614.2552393669 19604.270420603 19784.546399614 19774.484616757 19764.47995576 19754.580961511 19744.6278067713 19734.7685820877 19724.7957087158 19714.8118147383 19704.8518237449 19694.8947734887 19684.9441602588 19674.9757754289 19665.048395696 19655.0151124361 19645.1786270248 19635.083411848 19625.1880716432 19615.3814948731 19605.0374055349 19783.8838785591 19773.8956900509 19763.8964692669 19753.922028648 19743.8882123569 19733.924155679 19723.9324021681 19713.932104258 19703.9025204189 19693.8991846811 19683.8893615239 19673.875031869 19663.8807406531 19653.861049164 19643.868992975 19633.848782399 19623.8714840411 19613.885345397 19603.916953172 19783.7888825619 19773.812500373 19763.9081160121 19753.8085488721 19743.807994935 19733.8849943329 19723.8466772421 19713.8259622251 19703.801582653 19693.773460001 19683.7782304139 19673.7686207529 19663.7495348571 19653.760583648 19643.7670843699 19633.788996565 19623.823666088 19613.8856225131 19603.9077042329 19784.0366010839 19774.005290418 19764.0077389471 19754.0330145629 19744.000460803 19734.137437795 19724.082807844 19714.1031462929 19704.128807176 19694.173561413 19684.161687403 19674.2034662751 19664.2336434839 19654.249453555 19644.326435619 19634.3539971901 19624.385448561 19614.4828459381 19604.50198595 19784.855845841 19774.810991519 19764.8373587579 19754.888471343 19744.8915906557 19734.89969379 19724.8893020193 19714.8950745608 19704.8995700246 19694.8644326333 19684.868782423 19674.8524989572 19664.871024855 19654.850827846 19644.8397604783 19634.8380800488 19624.8505325093 19614.8265553731 19604.8552384411 19783.842741783 19773.854311239 19763.8641455001 19753.877778414 19743.8182304581 19733.8959956699 19723.905401926 19713.8722450341 19703.870391622 19693.8546012139 19683.8286653779 19673.9068782151 19663.8205378359 19653.9515307039 19643.994375414 19634.001266072 19624.075961692 19614.124355641 19604.16401597 19783.922749583 19773.9316759431 19763.985411744 19754.0290180751 19744.018495372 19734.199380561 19724.128017777 19714.106720494 19704.0808876731 19694.0463547891 19684.045507048 19674.0529106939 19664.0475365589 19654.033983285 19644.037688787 19634.0595091239 19624.0731765511 19614.1009891049 19604.173244195 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 -5 0 5 10 15 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4 5.6 5.8 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0 8.2 8.4 8.6 8.8 9.0 9.2 9.4 9.6 9.8 10.0 10.2 10.4 10.6 10.8 11.0 LGasPCar

The same effect can be achieved using with_theme:

Gadfly.with_theme(latex_fonts) do
    gasoline = dataset("Ecdat", "Gasoline")
    plot(gasoline, x=:Year, y=:LGasPCar, color=:Country, Geom.point, Geom.line)
end

style

You can use style to override the fields of the current theme. Much like Theme's constructor, style inputs keyword arguments, returns a Theme, and can be used with push_theme, with_theme, and plot.

Gadfly.push_theme(style(line_width=1mm))
p1 = plot([sin,cos], 0, 2pi)
p2 = plot([sin,cos], 0, 2pi, style(line_width=2mm, line_style=[:dash]))
fig = hstack(p1,p2)
Gadfly.pop_theme()
x -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 -8.0 -7.5 -7.0 -6.5 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5 13.0 13.5 14.0 14.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