- Plotly - Discussion
- Plotly - Useful Resources
- Plotly - Quick Guide
- Plotly with Matplotlib and Chart Studio
- Plotly with Pandas and Cufflinks
- Plotly - FigureWidget Class
- Plotly - Slider Control
- Plotly - Adding Buttons/Dropdown
- Plotly - 3D Scatter & Surface Plot
- Plotly - OHLC Chart Waterfall Chart & Funnel Chart
- Plotly - Polar Chart & Radar Chart
- Plotly - Heatmap
- Plotly - Distplots, Density Plot & Error Bar Plot
- Plotly - Box Plot Violin Plot & Contour Plot
- Plotly - Histogram
- Plotly - Dot Plots & Table
- Plotly - Scatter Plot, Scattergl Plot & Bubble Charts
- Plotly - Bar Chart & Pie Chart
- Plotly - Subplots & Inset Plots
- Plotly - Format Axis & Ticks
- Plotly - Legends
- Plotly - Exporting to Static Images
- Plotly - Package Structure
- Plotting Inline with Jupyter Notebook
- Plotly - Online & Offline Plotting
- Plotly - Environment Setup
- Plotly - Introduction
- Plotly - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Plotly - Format Axis and Ticks
You can configure appearance of each axis by specifying the pne width and color. It is also possible to define grid width and grid color. Let us learn about the same in detail in this chapter.
Plot with Axis and Tick
In the Layout object’s properties, setting showticklabels to true will enable ticks. The tickfont property is a dict object specifying font name, size, color, etc. The tickmode property can have two possible values — pnear and array. If it is pnear, the position of starting tick is determined by tick0 and step between ticks by dtick properties.
If tickmode is set to array, you have to provide pst of values and labels as tickval and ticktext properties.
The Layout object also has Exponentformat attribute set to ‘e’ will cause tick values to be displayed in scientific notation. You also need to set showexponent property to ‘all’.
We now format the Layout object in above example to configure x and y axis by specifying pne, grid and title font properties and tick mode, values and font.
layout = go.Layout( title = "Sine and cos", xaxis = dict( title = angle , showgrid = True, zeropne = True, showpne = True, showticklabels = True, gridwidth = 1 ), yaxis = dict( showgrid = True, zeropne = True, showpne = True, gridcolor = #bdbdbd , gridwidth = 2, zeropnecolor = #969696 , zeropnewidth = 2, pnecolor = #636363 , pnewidth = 2, title = VALUE , titlefont = dict( family = Arial, sans-serif , size = 18, color = pghtgrey ), showticklabels = True, tickangle = 45, tickfont = dict( family = Old Standard TT, serif , size = 14, color = black ), tickmode = pnear , tick0 = 0.0, dtick = 0.25 ) )
Plot with Multiple Axes
Sometimes it is useful to have dual x or y axes in a figure; for example, when plotting curves with different units together. Matplotpb supports this with the twinx and twiny functions. In the following example, the plot has dual y axes, one showing exp(x) and other showing log(x)
x = np.arange(1,11) y1 = np.exp(x) y2 = np.log(x) trace1 = go.Scatter( x = x, y = y1, name = exp ) trace2 = go.Scatter( x = x, y = y2, name = log , yaxis = y2 ) data = [trace1, trace2] layout = go.Layout( title = Double Y Axis Example , yaxis = dict( title = exp ,zeropne=True, showpne = True ), yaxis2 = dict( title = log , zeropne = True, showpne = True, overlaying = y , side = right ) ) fig = go.Figure(data=data, layout=layout) iplot(fig)
Here, additional y axis is configured as yaxis2 and appears on right side, having ‘log’ as title. Resultant plot is as follows −
Advertisements