Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Placing ticklabels via tickvals and ticktext ##"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"See: https://plot.ly/python/reference/#layout-xaxis"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>"
],
"text/vnd.plotly.v1+html": [
"<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"from plotly.offline import download_plotlyjs, init_notebook_mode, iplot, plot\n",
"init_notebook_mode(connected=True)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"x=np.linspace(0, 90000, 40)\n",
"y= 200+100*np.random.rand(40)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"tickvals=[3461+k*6923 for k in range(13)]\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"ticktext=['0-3460', '3460-10K', '10K-17K','17K-24K', '24K-31K', '31K-38K', '38K-45K', '45K-51K', '51K-58K',\n",
" '58K-65K', '65K-72K', '72K-79K', '79K-86K']"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"data=[dict(x=x,\n",
" y=y,\n",
" mode='markers+lines',\n",
" marker=dict(color='blue', size=6),\n",
" \n",
" )]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"layout=dict(width=800, height=600, autosize=False,\n",
" xaxis=dict(zeroline=False,\n",
" showline=True, \n",
" tickmode='array',\n",
" tickvals=tickvals, \n",
" ticktext=ticktext,\n",
" ticklen=4, mirror=True),\n",
" yaxis=dict(showline=True, mirror=True),\n",
" hovermode='closest'\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"marker": {
"color": "blue",
"size": 6
},
"mode": "markers+lines",
"x": [
0,
2307.6923076923076,
4615.384615384615,
6923.076923076923,
9230.76923076923,
11538.461538461539,
13846.153846153846,
16153.846153846152,
18461.53846153846,
20769.23076923077,
23076.923076923078,
25384.615384615383,
27692.30769230769,
30000,
32307.692307692305,
34615.38461538462,
36923.07692307692,
39230.76923076923,
41538.46153846154,
43846.153846153844,
46153.846153846156,
48461.53846153846,
50769.230769230766,
53076.92307692308,
55384.61538461538,
57692.30769230769,
60000,
62307.692307692305,
64615.38461538461,
66923.07692307692,
69230.76923076923,
71538.46153846153,
73846.15384615384,
76153.84615384616,
78461.53846153845,
80769.23076923077,
83076.92307692308,
85384.61538461538,
87692.30769230769,
90000
],
"y": [
270.08954999791774,
285.93590111972105,
228.1668910063177,
254.40599540187964,
297.48520151161716,
220.87343371717498,
247.1617807914156,
289.96737747202883,
265.9751882459649,
227.9868933483244,
273.6586862234374,
240.9830826795224,
261.46718491023654,
242.76421730465506,
225.88706551472842,
270.1260319151751,
225.7647556579036,
295.6465475686623,
222.54307110237218,
295.3256901935455,
241.0771807623201,
268.2076989416837,
258.5568603853352,
247.96482473886746,
236.2989454093982,
266.02591421092364,
235.24173789895772,
257.49514563802137,
298.46906421520436,
266.61381470108563,
296.29585143849124,
298.1284566708218,
235.81370193419866,
225.12148716750488,
293.0180287182877,
235.77449133842458,
225.511318358511,
241.73389609057455,
276.6146233356744,
271.25810320198207
]
}
],
"layout": {
"autosize": false,
"height": 600,
"hovermode": "closest",
"width": 800,
"xaxis": {
"mirror": true,
"showline": true,
"ticklen": 4,
"tickmode": "array",
"ticktext": [
"0-3460",
"3460-10K",
"10K-17K",
"17K-24K",
"24K-31K",
"31K-38K",
"38K-45K",
"45K-51K",
"51K-58K",
"58K-65K",
"65K-72K",
"72K-79K",
"79K-86K"
],
"tickvals": [
3461,
10384,
17307,
24230,
31153,
38076,
44999,
51922,
58845,
65768,
72691,
79614,
86537
],
"zeroline": false
},
"yaxis": {
"mirror": true,
"showline": true
}
}
},
"text/html": [
"<div id=\"7bf83514-09f2-452a-a82e-e2de5fe4f473\" style=\"height: 600px; width: 800px;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"7bf83514-09f2-452a-a82e-e2de5fe4f473\", [{\"marker\": {\"color\": \"blue\", \"size\": 6}, \"y\": [270.08954999791774, 285.93590111972105, 228.1668910063177, 254.40599540187964, 297.48520151161716, 220.87343371717498, 247.1617807914156, 289.96737747202883, 265.9751882459649, 227.9868933483244, 273.6586862234374, 240.9830826795224, 261.46718491023654, 242.76421730465506, 225.88706551472842, 270.1260319151751, 225.7647556579036, 295.6465475686623, 222.54307110237218, 295.3256901935455, 241.0771807623201, 268.2076989416837, 258.5568603853352, 247.96482473886746, 236.2989454093982, 266.02591421092364, 235.24173789895772, 257.49514563802137, 298.46906421520436, 266.61381470108563, 296.29585143849124, 298.1284566708218, 235.81370193419866, 225.12148716750488, 293.0180287182877, 235.77449133842458, 225.511318358511, 241.73389609057455, 276.6146233356744, 271.25810320198207], \"mode\": \"markers+lines\", \"x\": [0.0, 2307.6923076923076, 4615.384615384615, 6923.076923076923, 9230.76923076923, 11538.461538461539, 13846.153846153846, 16153.846153846152, 18461.53846153846, 20769.23076923077, 23076.923076923078, 25384.615384615383, 27692.30769230769, 30000.0, 32307.692307692305, 34615.38461538462, 36923.07692307692, 39230.76923076923, 41538.46153846154, 43846.153846153844, 46153.846153846156, 48461.53846153846, 50769.230769230766, 53076.92307692308, 55384.61538461538, 57692.30769230769, 60000.0, 62307.692307692305, 64615.38461538461, 66923.07692307692, 69230.76923076923, 71538.46153846153, 73846.15384615384, 76153.84615384616, 78461.53846153845, 80769.23076923077, 83076.92307692308, 85384.61538461538, 87692.30769230769, 90000.0]}], {\"autosize\": false, \"yaxis\": {\"showline\": true, \"mirror\": true}, \"height\": 600, \"width\": 800, \"xaxis\": {\"tickmode\": \"array\", \"ticklen\": 4, \"mirror\": true, \"zeroline\": false, \"showline\": true, \"ticktext\": [\"0-3460\", \"3460-10K\", \"10K-17K\", \"17K-24K\", \"24K-31K\", \"31K-38K\", \"38K-45K\", \"45K-51K\", \"51K-58K\", \"58K-65K\", \"65K-72K\", \"72K-79K\", \"79K-86K\"], \"tickvals\": [3461, 10384, 17307, 24230, 31153, 38076, 44999, 51922, 58845, 65768, 72691, 79614, 86537]}, \"hovermode\": \"closest\"}, {\"linkText\": \"Export to plot.ly\", \"showLink\": true})});</script>"
],
"text/vnd.plotly.v1+html": [
"<div id=\"7bf83514-09f2-452a-a82e-e2de5fe4f473\" style=\"height: 600px; width: 800px;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"7bf83514-09f2-452a-a82e-e2de5fe4f473\", [{\"marker\": {\"color\": \"blue\", \"size\": 6}, \"y\": [270.08954999791774, 285.93590111972105, 228.1668910063177, 254.40599540187964, 297.48520151161716, 220.87343371717498, 247.1617807914156, 289.96737747202883, 265.9751882459649, 227.9868933483244, 273.6586862234374, 240.9830826795224, 261.46718491023654, 242.76421730465506, 225.88706551472842, 270.1260319151751, 225.7647556579036, 295.6465475686623, 222.54307110237218, 295.3256901935455, 241.0771807623201, 268.2076989416837, 258.5568603853352, 247.96482473886746, 236.2989454093982, 266.02591421092364, 235.24173789895772, 257.49514563802137, 298.46906421520436, 266.61381470108563, 296.29585143849124, 298.1284566708218, 235.81370193419866, 225.12148716750488, 293.0180287182877, 235.77449133842458, 225.511318358511, 241.73389609057455, 276.6146233356744, 271.25810320198207], \"mode\": \"markers+lines\", \"x\": [0.0, 2307.6923076923076, 4615.384615384615, 6923.076923076923, 9230.76923076923, 11538.461538461539, 13846.153846153846, 16153.846153846152, 18461.53846153846, 20769.23076923077, 23076.923076923078, 25384.615384615383, 27692.30769230769, 30000.0, 32307.692307692305, 34615.38461538462, 36923.07692307692, 39230.76923076923, 41538.46153846154, 43846.153846153844, 46153.846153846156, 48461.53846153846, 50769.230769230766, 53076.92307692308, 55384.61538461538, 57692.30769230769, 60000.0, 62307.692307692305, 64615.38461538461, 66923.07692307692, 69230.76923076923, 71538.46153846153, 73846.15384615384, 76153.84615384616, 78461.53846153845, 80769.23076923077, 83076.92307692308, 85384.61538461538, 87692.30769230769, 90000.0]}], {\"autosize\": false, \"yaxis\": {\"showline\": true, \"mirror\": true}, \"height\": 600, \"width\": 800, \"xaxis\": {\"tickmode\": \"array\", \"ticklen\": 4, \"mirror\": true, \"zeroline\": false, \"showline\": true, \"ticktext\": [\"0-3460\", \"3460-10K\", \"10K-17K\", \"17K-24K\", \"24K-31K\", \"31K-38K\", \"38K-45K\", \"45K-51K\", \"51K-58K\", \"58K-65K\", \"65K-72K\", \"72K-79K\", \"79K-86K\"], \"tickvals\": [3461, 10384, 17307, 24230, 31153, 38076, 44999, 51922, 58845, 65768, 72691, 79614, 86537]}, \"hovermode\": \"closest\"}, {\"linkText\": \"Export to plot.ly\", \"showLink\": true})});</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig=dict(data=data, layout=layout)\n",
"iplot(fig)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment