Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python plotly create a color scale related to max and min number of value

This is a code, I try to show a car speed for each point.

import plotly.plotly as py
from plotly.graph_objs import *

mapbox_access_token = 'MAPBOX API KEY'


data = Data([
    Scattermapbox(
        lat=dataframe_monday_morning['latitude'],
        lon=dataframe_monday_morning['longitude'],
        mode='markers',
        marker=Marker(
            size=5,
            color =dataframe_monday_morning['speed'],
            colorscale= 'YlOrRd',

            #opacity=0.3,
            symbol = 'circle',

        ),

    )
])
layout = Layout(
    autosize=True,
    hovermode='closest',
    width=1300,
        margin=go.Margin(
        l=0,
        r=0,
        b=0,
        t=0
        ),
    height=700,
    mapbox=dict(
        accesstoken=mapbox_access_token,
        bearing=0,#
        center=dict(
            lat=-36.7526,
            lon=174.7274
        ),
        pitch=0,
        zoom=16.2,
        style='dark',


    ),
)

fig = dict(data=data, layout=layout)
py.iplot(fig, filename='Multiple Mapbox')

but when I try

color =dataframe_monday_morning['speed']

code choose in current data min and max speed then gives me a graph. In data, some speed data gaps are very big so I would like to create a colour scale between my speed value. (e.g If you choose max speed 200km/h your other 30km/h and 90km/h looks similar colour but normally really different speed )

enter image description here

My question is how can I create a scale for choosing a colour for speed?

EDIT:

This is an example of data I edited.

13  1.464301e+10    2015-11-15 18:28:50 191 10051   76  -36.817540  174.750526      
14  1.464298e+10    2015-11-15 18:27:20 209 10051   48  -36.806104  174.759209      
15  1.464180e+10    2015-11-15 17:41:27 171 10051   0   -36.718553  174.713503  
16  1.464186e+10    2015-11-15 17:43:44 172 10051   25  -36.720747  174.713897  
17  1.464238e+10    2015-11-15 18:05:36 137 10051   5   -36.753691  174.728945  
18  1.464199e+10    2015-11-15 17:49:22 170 10051   0   -36.728252  174.715084  
19  1.464279e+10    2015-11-15 18:20:41 153 10051   20  -36.787389  174.752337  
20  1.464229e+10    2015-11-15 18:01:47 146 10051   16  -36.749369  174.724865  
21  1.464298e+10    2015-11-15 18:27:39 216 10051   51  -36.807940  174.757603  
22  1.464254e+10    2015-11-15 18:11:35 162 10051   36  -36.765195  174.739728  
23  1.464301e+10    2015-11-15 18:28:37 197 10051   66  -36.815369  174.751177  
like image 280
Axis Avatar asked May 08 '17 04:05

Axis


People also ask

How do you use color scales in Plotly?

Color Scales in Plotly ExpressBy default, Plotly Express will use the color scale from the active template's layout. colorscales. sequential attribute, and the default active template is plotly which uses the Plasma color scale. You can choose any of the built-in color scales, however, or define your own.

How do you add a marker in Plotly?

Add Marker Border This can be achieved by adding the line property to the marker object. Here is an example of adding a marker border to a faceted scatter plot created using Plotly Express. Here is an example that creates an empty graph object figure, and then adds two scatter traces with a marker border.

How do you increase your Figsize in Plotly?

One of the best ways to modify the size of the Plotly figure is by adjusting the width and the height parameters. We will start by discussing how to change the height and width parameters using Plotly Express. For example, in the following code, we create a simple line chart using the default Plotly's dimensions.

What is PX scatter?

With px. scatter , each data point is represented as a marker point, whose location is given by the x and y columns. # x and y given as array_like objects import plotly.express as px fig = px.


1 Answers

Not 100% sure if I got the question right but you could try adding

showscale=True,
cmax=200,
cmin=0

to your Marker object to get a graph with a colorbar with fixed max and min values.

enter image description here

like image 111
Maximilian Peters Avatar answered Nov 16 '22 03:11

Maximilian Peters