Geoviews points: changing colormap with high and low options - bokeh

I recently looked at this question on manually setting the limits of a holoviews colorbar, but after changing the range on one of my vdims, it didn't change the high and low limits of the colorbar. Is there a way to pass a Bokeh LinearColorMapper (and its options) directly for a particular vdim?
opts = {'plot' : dict(width=width_val, height=height_val, tools=[hover_shipments],
size_index='po_qty',
color_index='magnitude',
size_fn=(lambda x : x/100),
click_policy='hide', colorbar=True),
'style': dict(cmap='Viridis', line_width=0.25, alpha=0.75, fill_alpha=0.75,
muted_alpha=0.05)}
ds_time_store.to(gv.Points,
kdims=['longitude_qty','latitude_qty'],
vdims=['store_num',
'city_nm',
'po_qty',
hv.Dimension('magnitude', range=(0, 50))], label='late').opts({'Points' : opts})

By calling redim(aggregate_rating=dict(range=(0, 5))) on my data set locality_ratings before setting up the Points, I was able to set the boundaries for the colorbar from 0 to 5 as per my ratings.
points = locality_ratings.redim(aggregate_rating=dict(range=(0, 5))).to(gv.Points, ['longitude', 'latitude'],
['aggregate_rating', 'votes', 'cuisine_count', 'average_cost_for_two', 'price_range', 'locality'])
(gts.Wikipedia * points.options(width=700, height=600,
tools=['hover', 'save', 'zoom_in', 'zoom_out', 'pan' , 'wheel_zoom'],
colorbar=True, toolbar='above', xaxis=None, yaxis=None,
size_index=3, color_index=2, size=3, cmap=bokeh.palettes.all_palettes['Dark2'][5])).redim(longitude="Longitude",
latitude="Latitude",
aggregate_rating='Rating',
locality="Locality",
votes="Votes",
price_range="Price Range",
average_cost_for_two="Avg. Cost for 2 (R)",
cuisine_count="No. Cuisines"
)

Related

Plotting multiple states bokeh

I'm trying to plot two things:
Counties for MD, VA, and DC
Lats/Longs for housing listings in that area (most expensive in a certain color
and least expensive in another color)
However, I'm having trouble with part 1, and cannot seem to plot the counties without getting the error message:
"Javascript error adding output!
Error: Error rendering Bokeh model: could not find tag with id: xxxxxxxxxxx
See your browser Javascript console for more details."
where xxxxx are numbers
from bokeh.io import show
from bokeh.models import (
ColumnDataSource,
HoverTool,
LogColorMapper)
from bokeh.palettes import Viridis6 as palette
from bokeh.plotting import figure
from bokeh.sampledata.us_counties import data as counties
from bokeh.sampledata.unemployment import data as unemployment
palette.reverse()
va_counties = {
code: county for code, county in counties.items() if county["state"] == "va"
}
md_counties = {
code: county for code, county in counties.items() if county["state"] == "md"
}
dc_counties = {
code: county for code, county in counties.items() if county["state"] == "dc"
}
va_county_xs = [county["lons"] for county in va_counties.values()]
va_county_ys = [county["lats"] for county in va_counties.values()]
md_county_xs = [county["lons"] for county in md_counties.values()]
md_county_ys = [county["lats"] for county in md_counties.values()]
dc_county_xs = [county["lons"] for county in dc_counties.values()]
dc_county_ys = [county["lats"] for county in dc_counties.values()]
va_county_names = [county['name'] for county in va_counties.values()]
md_county_names = [county['name'] for county in md_counties.values()]
dc_county_names = [county['name'] for county in dc_counties.values()]
#county_rates = [unemployment[county_id] for county_id in counties]
color_mapper = LogColorMapper(palette=palette)
va_source = ColumnDataSource(data=dict(
x=va_county_xs,
y=va_county_ys,
name=va_county_names,
))
md_source = ColumnDataSource(data=dict(
x=md_county_xs,
y=md_county_ys,
name=md_county_names,
))
dc_source = ColumnDataSource(data=dict(
x=dc_county_xs,
y=dc_county_ys,
name=dc_county_names,
))
TOOLS = "pan,wheel_zoom,reset,hover,save"
va = figure(
title="Texas Unemployment, 2009", tools=TOOLS,
x_axis_location=None, y_axis_location=None
)
va.grid.grid_line_color = None
md = figure(
title="Texas Unemployment, 2009", tools=TOOLS,
x_axis_location=None, y_axis_location=None
)
md.grid.grid_line_color = None
dc = figure(
title="Texas Unemployment, 2009", tools=TOOLS,
x_axis_location=None, y_axis_location=None
)
dc.grid.grid_line_color = None
va.patches('x', 'y', source=va_source,
fill_color={'field': 'rate', 'transform': color_mapper},
fill_alpha=0.7, line_color="white", line_width=0.5)
md.patches('x', 'y', source=md_source,
fill_color={'field': 'rate', 'transform': color_mapper},
fill_alpha=0.7, line_color="white", line_width=0.5)
dc.patches('x', 'y', source=dc_source,
fill_color={'field': 'rate', 'transform': color_mapper},
fill_alpha=0.7, line_color="white", line_width=0.5)
hover = p.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = [
("Name", "#name"),
("(Long, Lat)", "($x, $y)"),
]
show(va)
show(md)
show(dc)
Bokeh maintains an implicit "current document" and by default everything you make gets added to that. This makes it very simple to have a script that generates one HTML file, and especially makes usage in the Jupyter notebook much more simple and transparent. In general this is a net positive, but it does make certain other usage patterns need to be slightly more verbose. In particular in your case with multiple show calls, each call to show gets the same document which is probably not what you intend. The solution is to create and show each plot in order, and call reset_output in between. Additionally, you would really need to specify unique filenames for each separate output, by using output_file. Here is a small complete example:
from bokeh.io import output_file, reset_output, show
from bokeh.plotting import figure
# create and show one figure
p1 = figure(title="plot 1")
p1.circle([1,2,3], [4,6,5])
output_file("p1.html")
show(p1)
# clear out the "current document"
reset_output()
# create and show another figure
p2 = figure(title="plot 2")
p2.circle([1,2,3], [8,6,7])
output_file("p2.html")
show(p2)
There are other ways to do this by managing Bokeh Document objects explicitly yourself, but I would probably say this is the simplest to get started.

Plot with specifics X-axis values in R

I have these two series:
y=c(-1.5998643938095, -1.63502358201045, -1.69216952874043, -1.74137547219013,
-1.81603466811487, -1.83290876564814, -1.82119795752288, -1.68504242312903,
-1.64136028883498, -1.5460994846518, -1.53661006904405, -1.52831783563943,
-1.52603247050589, -1.52268205493272, -1.5212011956198, -1.51432268622967,
-1.51379366677634, -1.50908788843249, -1.48822428255097, -1.48769228523642,
-1.48483387454842, -1.48453062065826, -1.48339797802088, -1.48119621507587,
-1.48110046708904, -1.48060635307086, -1.47995343813638, -1.47994119367829,
-1.47941156884319, -1.47938925858236, -1.47938695218289, -1.47937696658098,
-1.47698623662183, -1.47698623662183, -1.47567307555111, -1.47483038921359,
-1.4736380690598, -1.47292362741829, -1.47215618888986, -1.47149860750148,
-1.47110996638024, -1.47050643723499, -1.46953281801724, -1.46825152829741,
-1.46724698190091, -1.46703097959397, -1.46648175185516, -1.4664413436873,
-1.46607836828396, -1.465853817256, -1.46559489002899, -1.46401962782667,
-1.46227935977164, -1.46210742960601, -1.46176056274246, -1.46114880053774,
-1.46050710466594, -1.45930618888587, -1.45930470729008, -1.45880976260809,
-1.4582337419082, -1.45649254752875, -1.45592179387283, -1.45591600470178,
-1.45487189856011, -1.45305608952432, -1.45301369078264, -1.45282998956255,
-1.45264299648548, -1.451492927921, -1.45136310047362, -1.45091392143768,
-1.45069600456254, -1.45041739845932, -1.45021222131199, -1.45015797613347,
-1.44855512307855, -1.44786178854079, -1.44781922895741, -1.44771771838997,
-1.44712449747479, -1.44691700015014, -1.44682684210453, -1.44678284793857,
-1.44605119420611, -1.4460226868879, -1.44571074258618, -1.4452512583365,
-1.4451833273209, -1.44347252955088, -1.44346529086636, -1.44334836577964,
-1.44283234085434, -1.44282090886531, -1.44277303333844, -1.44276726368483,
-1.44226898300518, -1.44226143122353, -1.44164469533319, -1.44040718820924,
-1.44007152267034, -1.43891940826629, -1.43878784348646, -1.43720486744441,
-1.43682534475562, -1.43589722283182, -1.43553231203842, -1.43551864711074,
-1.43536737759472, -1.43509079079168, -1.4345130019316, -1.43322388529487,
-1.432492553991, -1.43198101748486, -1.43119406845686, -1.43098345123839,
-1.43067674410408, -1.43065237690907, -1.4301008969997, -1.42957895243291,
-1.42913557509501, -1.42876420101235, -1.428101540577, -1.42690855108318,
-1.42682882777193, -1.42667868057341, -1.42647659641895, -1.42642967286365,
-1.42638266289136, -1.42584441450912, -1.42551888935884, -1.42500303556265,
-1.42480971466621, -1.42267013220422, -1.42267013220422, -1.42254423649875,
-1.42227372076633, -1.42158579496348, -1.42155981729155, -1.42135043822943,
-1.42119996091157, -1.42059723196635, -1.42054112251372, -1.42037987610062,
-1.41988720557195, -1.41846642148337, -1.41768721977366, -1.41712074818823,
-1.41627221053046, -1.41617302141734, -1.41572980388805, -1.41569378376846,
-1.41501464816207, -1.41447894688003, -1.4136309327905, -1.41269319137196,
-1.41244179359642, -1.41174146820488, -1.41160740222662, -1.41087908191835,
-1.40917254185178, -1.40832530647502, -1.4082042201926, -1.40811332516486,
-1.40739105306066, -1.40646631308617, -1.40619992858907, -1.40548285389421,
-1.40432981273198, -1.40395132544927, -1.40330583018292, -1.4018786113105,
-1.40087144478313, -1.40075829454372, -1.39971935185189, -1.39748597997321,
-1.39739889942328, -1.39701887658488, -1.39673333360165, -1.39597258502012,
-1.39527409663982, -1.39527409663982, -1.39521541653476, -1.39494364585368,
-1.39469676119322, -1.39373022314479, -1.39271653652864, -1.39161201283438,
-1.39071339847077, -1.38974369953502, -1.38974198938904, -1.3894039853713,
-1.38873594971682, -1.38871885550179, -1.38706886032285, -1.38511170778675,
-1.38508010967343, -1.38496145433921, -1.38466062692511, -1.38416734067824,
-1.3840782779473, -1.38357525629763, -1.38355302746992, -1.38353420843684,
-1.383388989057, -1.38258701035437, -1.38257742645876, -1.38181544272521,
-1.38159360170984, -1.38156609412851, -1.38156609412851, -1.38148824778747,
-1.3805734083841, -1.37970027728057, -1.37955332492153, -1.379454592592,
-1.37861459579946, -1.37810315557753, -1.37738786297457, -1.37660472268844,
-1.37651708913807, -1.37642818076612, -1.37623249287843, -1.37574714054356,
-1.3752624355825, -1.3747435769979, -1.37453801843614, -1.37254136161746,
-1.37235596806715, -1.3711739927774, -1.37052673385029, -1.37017932312331,
-1.36919201276548, -1.36874374952405, -1.36870992034192, -1.36844834441028,
-1.36788940896553, -1.36785426309333, -1.3665578175658, -1.36645921657519,
-1.36643624494696, -1.36589729865879, -1.36516580262407, -1.36503720674118,
-1.36489868565419, -1.36481952736318, -1.36395080864832, -1.363101107146,
-1.36205871878833, -1.36205871878833, -1.36205871878833, -1.36165654176623,
-1.36089141765738, -1.36029386367878, -1.36017551723156, -1.35999818678069,
-1.35946012258471, -1.35888403119299, -1.35828482609332, -1.35825234586256,
-1.3581827654594, -1.35730517576928, -1.35665109196707, -1.35628426072835,
-1.35490181358604, -1.35397726821586, -1.35334393340595, -1.35190821970445,
-1.35176594335257, -1.35089065628399, -1.3505684993716, -1.34900490104273,
-1.34844563384622, -1.34820550365266, -1.34765699737468, -1.34717250009988,
-1.34694752405214, -1.346257020983, -1.34542246918757, -1.34524213174669,
-1.34499274521234, -1.34381094932539, -1.34299675617037, -1.34280350149617,
-1.34087387767563, -1.340820302186, -1.3407666747206, -1.34014217614603,
-1.33938017259306, -1.33664668609038, -1.33438784936148, -1.33401995755851,
-1.33219273302297, -1.33164764813041, -1.33130553790835, -1.32349613212725,
-1.32184064011115, -1.32113456827605, -1.32055011726724, -1.31719895484054,
-1.31594392214064, -1.31445046615048, -1.31316132337202, -1.31258538304814,
-1.31112328783767, -1.30942010507318, -1.30935376099677, -1.30711833222081,
-1.30099326665383, -1.29430541524941, -1.29411365144108, -1.29281795899985,
-1.28697399928846, -1.28603198919379, -1.27857366187536, -1.27746901606705,
-1.26691154549586, -1.26671698360671, -1.26354472778279, -1.2603364460369,
-1.25092528378555, -1.24695579775789, -1.24019070943844, -1.23079299277569,
-1.22956993851601, -1.22139097947348, -1.16699470736508, -1.15715630822687,
-1.1138992347869, -1.1120938250391, -1.11149401624673, -1.11061636683127,
-1.09344632136235, -1.08756453012044, -1.08549289617345, -1.08454018783343,
-1.07512596404849, -1.07512596404849, -1.0676800449532, -1.06077022887154,
-1.05993585559515, -1.05954653080575, -1.05877503597449, -1.05104470102228,
-1.05046086258739, -1.04018538596825, -1.03837204337853, -1.03183636170358,
-1.02994363068208, -1.01350321426957, -1.00522205124862, -1.00238188834357,
-1.0004040373221, -0.994823454508715, -0.987020715876091, -0.975102717941364,
-0.915104263694582)
And..
x=c(-2.13408282124157, -2.10180387024075, -2.08709542846115, -2.06581854776859,
-1.96940594614023, -1.92059021455153, -1.77135750098858, -1.44724137769461,
-1.2561207566961, -1.23337106615069, -1.23337106615069, -1.21033271987616,
-1.17224190869418, -0.987287130986902, -0.930654101673922, -0.84032098938398,
-0.804222173279778, -0.710880557798421, -0.710274602839522, -0.645609892110399,
-0.642339799195257, -0.561068221654604, -0.560578241710363, -0.468376211115928,
-0.399891346669179, -0.367962749987316, -0.357654677323427, -0.355526612996049,
-0.351157363516097, -0.339040162099913, -0.32576940070479, -0.31005225147438,
-0.300801122021865, -0.276367335916672, -0.273291307860379, -0.271941099001061,
-0.263092638078222, -0.252094919104229, -0.251870071377791, -0.244196231236371,
-0.242285085575067, -0.238637134733422, -0.237815138595843, -0.237707612367788,
-0.23432778199568, -0.233217616922032, -0.215005504969912, -0.190866190595962,
-0.174905786573687, -0.170624208572523, -0.131294039411123, -0.117326122090256,
-0.117002216501616, -0.102190096136279, -0.0954983190266434,
-0.0733445959504531, -0.0716155723656131, -0.0680478150792529,
-0.0630073983523438, -0.0584788679112602, -0.0476709638805417,
-0.0438622752498619, -0.0437253997185527, -0.0291385761624463,
-0.0242507098145106, -0.0048903409937795, 0.00974462641756269,
0.0145813294186947, 0.0191057613829981, 0.0191057613829981, 0.0340295342494246,
0.0388002234009033, 0.0390062958543158, 0.0439060968485894, 0.0488066270410537,
0.0581074648913438, 0.0582524295135167, 0.0587023477645277, 0.0794771765507019,
0.0874941852878619, 0.0942884601795813, 0.0971744448796663, 0.112591008607521,
0.115842601451899, 0.117777334985236, 0.120771558153887, 0.121770277454725,
0.131705777270685, 0.136069937654382, 0.138715918637033, 0.146100082885714,
0.147931378168731, 0.148667996209384, 0.150916408652968, 0.152229184039054,
0.152311932374882, 0.189979710534138, 0.204491672280449, 0.209335715822045,
0.212781594082023, 0.228408594592633, 0.243685261274695, 0.249826157122035,
0.26726146729783, 0.273070276461485, 0.277333935754953, 0.27907302119492,
0.284122902094142, 0.285831240218903, 0.300744495063032, 0.302615826638597,
0.316903925614609, 0.320509604802921, 0.322872541898245, 0.330784178217236,
0.333766357672927, 0.345304107081801, 0.345877256751881, 0.349432731942789,
0.353197839664365, 0.354444636851614, 0.358851959954376, 0.3658498883919,
0.373268414067618, 0.38424809747668, 0.388983450149616, 0.394013220107969,
0.397590808408466, 0.412049695447969, 0.412768116506701, 0.416848382330892,
0.42027883004796, 0.421508760309064, 0.421527151545797, 0.421645948355298,
0.42562359144529, 0.427993002373839, 0.427993002373839, 0.434468715001324,
0.451153129776927, 0.451723596325215, 0.452207713574837, 0.477471014343611,
0.48536961901946, 0.509554221440034, 0.509990112983694, 0.511967275223757,
0.513742133279682, 0.524298253524225, 0.544899577957136, 0.563480822566143,
0.571794602730202, 0.571923720884548, 0.580124428414375, 0.583617519186519,
0.591790353012289, 0.59196029661932, 0.59641022416288, 0.617442207769692,
0.620039023859364, 0.620952462500557, 0.639275095589231, 0.657250960061062,
0.65839848539968, 0.692343534139961, 0.695113023080762, 0.725170528079677,
0.725320511648619, 0.749589157782804, 0.749770885706225, 0.753784936674951,
0.772144044737755, 0.789132280758831, 0.789761901470021, 0.794009192254919,
0.794513883636316, 0.811138663637867, 0.832685174624292, 0.833271275360215,
0.841995542626672, 0.84738776062292, 0.865301594531753, 0.874522732571248,
0.875907748464799, 0.885710940918139, 0.890898165782206, 0.894224361543627,
0.896020924376706, 0.902012952708064, 0.909520128859853, 0.917580402008,
0.919811467591702, 0.920518946695403, 0.920778343382245, 0.921672761153802,
0.941624282339792, 0.954859464432611, 0.955646928144893, 0.95757172328681,
0.96088264590577, 0.962260761219502, 0.978805354690393, 0.980152400103274,
0.986436341094521, 1.00701910754948, 1.01347603677282, 1.02104466788544,
1.02327847242141, 1.02505412726133, 1.03096110370269, 1.03693923160162,
1.04921144723666, 1.04941517861614, 1.05865253464199, 1.07538216096668,
1.07558813014312, 1.07971110445062, 1.08482603401352, 1.08720790601906,
1.09986925913665, 1.10222235572373, 1.10535734670845, 1.1068372891502,
1.11964763689349, 1.13204543352827, 1.13712797493968, 1.137994313651,
1.14283365452046, 1.15327223047834, 1.16216148806749, 1.16440730747853,
1.16458533096955, 1.18155509540894, 1.20646482320366, 1.21736715796419,
1.22135166299098, 1.22205189547215, 1.22486491835871, 1.24031991107987,
1.25696163373374, 1.26430032405644, 1.26873147674325, 1.27266380857822,
1.27295500837028, 1.27394783802912, 1.27500526922897, 1.28563176302763,
1.30001778706583, 1.32102004599264, 1.33852067745566, 1.33988606590512,
1.34837748840695, 1.37602344513676, 1.38099152137314, 1.39304674741183,
1.40302514972963, 1.41193674468807, 1.41974582210249, 1.42095571632166,
1.43652509092991, 1.4408775844686, 1.44555422991457, 1.46029420906855,
1.46073814063481, 1.46329969139498, 1.46490559979866, 1.46585183789929,
1.47089773550726, 1.49381967453743, 1.4947688838941, 1.50293745878987,
1.51953897005108, 1.52493287754767, 1.52752856759917, 1.52900499548279,
1.53225964130144, 1.53280996843186, 1.5398514209443, 1.54594412948084,
1.55072368623232, 1.56980436455521, 1.5719982103876, 1.59015951604917,
1.59721359655012, 1.60687668483233, 1.61297695511031, 1.61443451813017,
1.63267938631648, 1.63639148926984, 1.64258181632699, 1.65298161250365,
1.67637046221758, 1.73372533918148, 1.7776936607558, 1.777773570246,
1.79995468792684, 1.82143061809024, 1.89764633131002, 1.90804519662853,
1.94921719591175, 2.02385761967456, 2.07464798866137, 2.08044125516482,
2.17193673385774, 2.19983327769389, 2.22936772843119, 2.2497967207606,
2.25041829923514, 2.26014008750837, 2.30633809611926, 2.34532730946189,
2.36846119815433, 2.39824708624861, 2.45599570773836, 2.4590828258477,
2.46707130963524, 2.4704638806704, 2.48819121085144, 2.51522660432035,
2.51991090204093, 2.53711294955152, 2.56907217758531, 2.60812454619044,
2.60956475684073, 2.62822938421567, 2.63585448081955, 2.73357252145678,
2.76421196010355, 2.77474221788829, 2.86426659827852, 2.8677328167048,
2.87108136656242, 2.99103441124555, 3.00554690183426, 3.0160909248325,
3.04462614144865, 3.10435865238545, 3.10449773118004, 3.12367577101729,
3.13587656152066, 3.13629766043355, 3.15861228566874, 3.15976692019742,
3.16072755978949, 3.16596254872079, 3.22189824909798, 3.22482598444997,
3.25247702481879, 3.28793314892395, 3.32070992405156, 3.32109018836231,
3.4822436996101)
I want to plot this graph.
plot(y,xaxt="n", type="l")
What I want here is to fill the x-axis with the values of the second series x, but I dont want to change the shape of the graph. I tried use the axis function but I could not done.
I just canĀ“t do this.
Any help?
The problem you are running into is that plot(x, xaxt="n") makes the x-axis range from 1 to length(y). When you try to superimpose your own values with axis(1, at=x) your ticks are being placed at the values of x which range from -2 to 3.5 ish. what you need to do is set the labels as x at index of y.
Something like:
plot(y, xaxt="n")
axis(1, at=seq_along(y), labels=x)
Now your example data is not of the same length so this will not work immediately.
Second, #Tim Biegeleisen's answer is far simpler and is prettier.
This is my suggestion:
#First, I have to get that the length of "y" and "x" are the same
y<-head(y,-(length(y)-length(x)))
#I plot your data
plot(y, xaxt="n",las=2,type="l")
#I configure the labels for avoid overlapping
axis(1, at=seq_along(y), labels=replace(x,rep(c(FALSE,rep(TRUE,7)),length.out=length(y)),""),las=2,cex.axis=0.5)

graph axis scaling incorrect when putting two Y axis on graph

Can someone explain why my plot apparently overwrites the first line with the second? The values are in no way the same.
per.acc<-c(0.508407842930696, 0.508407842930696, 0.508776550216615, 0.508895063272804,
0.509619309727288, 0.51039622865119, 0.510712263467692, 0.511871057794867,
0.512252933198141, 0.513280046351773, 0.514122805862446, 0.514478345031011,
0.514768043612805, 0.515676643710249, 0.516084855348231, 0.51682226992007,
0.517757206252222, 0.519008177400877, 0.519890441263613, 0.520680528304868,
0.521286261703164, 0.522181693683254, 0.523024453193927, 0.524222751873165,
0.524420273633479, 0.524986502679712, 0.525631740430071, 0.52609262453747,
0.526777366639891, 0.52733042756877, 0.52788348849765, 0.528278532018277,
0.528673575538905, 0.529661184340475, 0.530569784437919, 0.531109677249444,
0.530833146785004, 0.531425712065946, 0.531280862775049, 0.53063562502469,
0.531465216418009, 0.531215022188278, 0.531188685953569, 0.53153105700478,
0.53180758746922, 0.532110454168368, 0.532005109229533, 0.532070949816305,
0.53233431216339, 0.532189462872493, 0.532307975928682, 0.532321144046036,
0.531741746882448, 0.531504720770071, 0.530214245269354, 0.529661184340475,
0.529002778472762, 0.529845537983434, 0.53054344820321, 0.529108123411596,
0.528186355196797, 0.527896656615004, 0.526830039109309, 0.526263810063075,
0.525091847618546, 0.524354433046707, 0.523538009770743, 0.522655745908008,
0.522036844392357, 0.520812209478411, 0.519640247033882, 0.518520957058769,
0.517335826496886, 0.515531794419352, 0.514715371143388, 0.51314836517823,
0.511831553442804, 0.510975625814777, 0.510040689482625, 0.508118144348902,
0.507104199312624, 0.505813723811907, 0.505168486061548, 0.504312558433521,
0.503311781514597, 0.502284668360964, 0.501297059559395, 0.500546476870202,
0.500072424645448, 0.499018975257107, 0.497886517164641, 0.496964748949843,
0.495516256040874, 0.494120435601322, 0.493383021029483, 0.492803623865896,
0.492421748462622, 0.492118881763474, 0.492026704941994, 0.491684333890784
)
num.pred<-c(38609L, 38609L, 38637L, 38646L, 38701L, 38760L, 38784L, 38872L,
38901L, 38979L, 39043L, 39070L, 39092L, 39161L, 39192L, 39248L,
39319L, 39414L, 39481L, 39541L, 39587L, 39655L, 39719L, 39810L,
39825L, 39868L, 39917L, 39952L, 40004L, 40046L, 40088L, 40118L,
40148L, 40223L, 40292L, 40333L, 40312L, 40357L, 40346L, 40297L,
40360L, 40341L, 40339L, 40365L, 40386L, 40409L, 40401L, 40406L,
40426L, 40415L, 40424L, 40425L, 40381L, 40363L, 40265L, 40223L,
40173L, 40237L, 40290L, 40181L, 40111L, 40089L, 40008L, 39965L,
39876L, 39820L, 39758L, 39691L, 39644L, 39551L, 39462L, 39377L,
39287L, 39150L, 39088L, 38969L, 38869L, 38804L, 38733L, 38587L,
38510L, 38412L, 38363L, 38298L, 38222L, 38144L, 38069L, 38012L,
37976L, 37896L, 37810L, 37740L, 37630L, 37524L, 37468L, 37424L,
37395L, 37372L, 37365L, 37339L)
plot(x=1:100,y=per.acc, main="RSI predicting trend",ylab=NA,xlab="RSI cutoff value",col="blue",type="p")
par(new=T)
plot(x=1:100,y=num.pred,axes=F,xlab=NA,main=NA,ylab=NA,col="red",type="p")
axis(side=4)
Because your per.acc and num.pred has perfect co-linearity:
plot(per.acc, num.pred)
Therefore, your second plot and first plot just differ by a vertical shift. When you do par(new = TRUE), they coincide.
On the other hand, if you do some random shuffling:
set.seed(0); num.pred <- sample(num.pred)
the issue goes away:

How to create an Excel-like smoothing in Gnuplot?

I got a data that has a lot of data points, no definite equation or fit just a lot of spikey data, I just wanna connect all those and create a smooth graphs using Gnuplot however, nothing could make the plot as smooth as those produced by MS Excel. How do I create an Excel-like smooth plot?
Gnuplot settings I used:
set terminal postscript eps enhanced font "FreeSerif,14" size 3.0in,1.7in
set output 'fig4a.eps'
set encoding iso_8859_1
set border linewidth .5
set xlabel '{/FreeSerif-BoldItalics d} {/FreeSerif-Bold ({\305})}'
set ylabel '{/FreeSerif-Bold {/Symbol D}{/FreeSerif-Bold C}_q (e/V)}'
set xrange [-8:8]
set xtics -8,2,8
set mxtics 2
set yrange [0:0.3]
set ytics 0,0.1,0.3
set mytics 2
set key at 1.42,-0.24 reverse
set style line 1 linewidth 0.5
plot for [n=2:4] 'fig4a.dat' u 1:n smooth cspline frequency w lines ls 1
replot
quit
These are the plots I have (the designs were a bit different, as I am still resolving smoothing problem)
Excel
Gnuplot (spline, cspline, mcspline (each of these produce similar output))
Some Selected Data points
Using: plot 'fig4a.dat' u 1:4 smooth cspline notitle w lines ls 1
Output:
Data points:
-8.09808994 -3.53E-07
-7.99108994 -1.02E-05
-7.88508994 -0.000162606
-7.77908994 -0.001377785
-7.67308994 -0.00552213
-7.56708994 -0.00499697
-7.46108994 0.0326345
-7.35408994 0.1168893
-7.24808994 0.186241
-7.14208994 0.205997
-7.03608994 0.191836
-6.93008994 0.151735
-6.82308994 0.106245
-6.71708994 0.086542
-6.61108994 0.104821
-6.50508994 0.155378
-6.39908994 0.192769
-6.29208994 0.17085
-6.18608994 0.133063
-6.08008994 0.093566
-5.97408994 0.091761
-5.86808994 0.171249
-5.76108994 0.20373
-5.65508994 0.139635
-5.54908994 0.117342
-5.44308994 0.142744
-5.33708994 0.111295
-5.23008994 0.047449
-5.12408994 0.017428002
-5.01808994 0.025381005
-4.91208994 0.07760701
-4.80608994 0.177550019
-4.69908994 0.221490023
-4.59308994 0.130530012
-4.48708994 0.022438001
-4.38108994 -0.004862101
-4.27508994 0.022498
-4.16908994 0.079377
-4.06208994 0.14604
-3.95608994 0.19269
-3.85008994 0.19097
-3.74408994 0.125244
-3.63808994 0.05851
-3.53108994 0.053151
-3.42508994 0.063857
-3.31908994 0.05646
-3.21308994 0.05375
-3.10708994 0.06817
-3.00008994 0.081894
-2.89408994 0.070248
-2.78808994 0.055941
-2.68208994 0.0445004
-2.57608994 0.029018
-2.46908994 0.034651
-2.36308994 0.05154
-2.25708994 0.051322
-2.15108994 0.053645993
-2.04508994 0.079479713
-1.93808994 0.110223123
-1.83208994 0.12952024
-1.72608994 0.123183
-1.62008994 0.100336
-1.51408994 0.0878377
-1.40708994 0.08143
-1.30108994 0.11223
-1.19508994 0.167822
-1.08908994 0.157034
-0.98308994 0.107838
-0.87708994 0.09736
-0.77008994 0.10481
-0.66408994 0.12359
-0.55808994 0.17554
-0.45208994 0.21844
-0.34608994 0.20774
-0.23908994 0.169731
-0.13308994 0.143784
-0.02708994 0.134956
0.07891006 0.136358
0.18491006 0.115993
0.29191006 0.1022772
0.39791006 0.130636
0.50391006 0.137051
0.60991006 0.108013
0.71591006 0.108763
0.82291006 0.147532
0.92891006 0.1658
1.03491006 0.160103
1.14091006 0.1589476
1.24691006 0.1353571
1.35391006 0.09032325
1.45991006 0.05464951
1.56591006 0.03587591
1.67191006 0.031322905
1.77791006 0.021403117
1.88491006 0.00489071
1.99091006 0.002355969
You can set the number of points to show in a spline with
set sample 1000

r lattice wireframe different colours under specific conditions

I plot data in a 3D form using wireframe from the lattice package to show the volatility term structure. Here is the data:
library(lattice)
con <- textConnection (" X1M X2M X3M X6M X9M X12M X18M X24M VSTOXX Euro.Stoxx.50
2006-04-14 14.850 15.076 15.462 15.950 16.396 16.700 17.146 17.968 15.068 3793.830
2006-04-21 16.468 15.028 15.476 15.900 16.342 16.858 17.402 18.030 14.930 3824.030
2006-04-28 14.576 15.070 14.560 15.552 15.996 16.262 16.850 17.630 14.810 3865.136
2006-05-05 14.806 14.990 14.770 15.584 16.132 16.378 16.868 17.668 14.906 3848.302
2006-05-12 15.944 14.968 14.734 15.260 15.840 15.582 16.496 17.338 15.028 3844.066
2006-05-19 27.708 18.316 17.466 17.250 17.412 17.478 17.796 17.646 19.204 3655.658
2006-05-26 23.756 20.862 19.650 19.922 19.348 19.256 19.362 19.330 22.732 3613.942
2006-06-02 23.172 21.504 20.720 21.046 20.332 20.188 20.054 20.404 22.078 3638.574
2006-06-09 24.972 22.898 22.366 22.416 21.448 21.204 20.788 21.146 23.168 3535.830
2006-06-16 28.138 24.660 23.888 23.330 22.604 22.010 21.850 22.248 25.150 3451.960
2006-06-23 21.114 20.606 20.256 19.898 19.820 19.954 20.350 21.168 21.194 3525.386
2006-06-30 20.722 20.188 19.884 19.566 19.360 19.438 19.808 20.088 20.508 3555.864
2006-07-07 18.348 18.380 18.574 18.702 18.552 19.038 19.374 19.806 18.370 3653.206
2006-07-14 21.944 19.834 19.922 19.660 19.606 19.740 20.096 20.332 19.960 3597.120
2006-07-21 24.876 21.276 21.160 20.654 20.536 20.746 21.008 21.330 21.224 3544.618
2006-07-28 18.506 18.696 18.642 19.106 19.332 19.806 20.248 20.644 18.606 3659.466
2006-08-04 18.718 18.934 18.914 19.282 19.292 19.714 20.080 20.470 18.878 3682.964
2006-08-11 20.586 19.798 19.534 19.666 19.504 19.736 20.154 20.570 19.878 3676.808
2006-08-18 19.258 17.696 18.112 18.452 18.628 19.080 19.698 20.068 17.566 3773.618
")
Dat<- read.table(con, header = TRUE)
I would like to show two following things in a 3D plot (separately) :
1.) I can simply control levels for which I have different colours by
data2<-Dat[,c(8,7,6,5,4,3,2,1)]
wireframe(as.matrix(data2),
aspect = c(61/87, 0.4), drape = TRUE,
scales = list(arrows = F, cex= 0.5, font = 1),
xlab='Date', ylab='Maturity', zlab='Value',
col.regions=c("#FF3030","#551A8B","#43CD80"),
at=c(0,18,25,30))
but how can I have different colours for the periods whith flat/steep/inverse term structure ?
2.) The data set actually represents 9 weeks before and after the 2006-06-16 (or any other date,not necessarilly 9 weeks time span ) and I would like to highlight this specific date either by different colour in a 3D plot or some arrow / text/...
Thanks,
Alexander

Resources