Plotly Tutorial
Selected Reading
- 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 - Legends
Plotly - Legends
By default, Plotly chart with multiple traces shows legends automatically. If it has only one trace, it is not displayed automatically. To display, set showlegend parameter of Layout object to True.
layout = go.Layoyt(showlegend = True)
Default labels of legends are trace object names. To set legend label exppcitly set name property of trace.
In following example, two scatter traces with name property are plotted.
import numpy as np import math #needed for definition of pi xpoints = np.arange(0, math.pi*2, 0.05) y1 = np.sin(xpoints) y2 = np.cos(xpoints) trace0 = go.Scatter( x = xpoints, y = y1, name= Sine ) trace1 = go.Scatter( x = xpoints, y = y2, name = cos ) data = [trace0, trace1] layout = go.Layout(title = "Sine and cos", xaxis = { title : angle }, yaxis = { title : value }) fig = go.Figure(data = data, layout = layout) iplot(fig)
The plot appears as below −
Advertisements