Giter VIP home page Giter VIP logo

pandas-bokeh's People

Contributors

ashton-sidhu avatar gwenzek avatar munehiro-k avatar patrikhlobil avatar toddrme2178 avatar toniskulj avatar verdimrc avatar vroger11 avatar wwymak avatar zifeo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pandas-bokeh's Issues

A few issues/enhancements for map plots

Hi Patrik,
Great library. I am a fan and have enjoyed using it so far. I have a few issues that might be able to help improve the geomap plots. I'd like to get your thoughts. I can split them up into different issues and submit PR's as well.

  1. Add support for scale_height argument for the map plots to allow for responsive sizing of the map

  2. The Reset Tool has unexpected behavior. It resets the aspect ratio of the maps, I would expect that the aspect ratio would be locked for maps. This can be solved by including match_aspect=True in the figure options.

figure_options = {
"title": title,
"x_axis_label": xlabel,
"y_axis_label": ylabel,
"plot_width": 600,
"plot_height": 400,
"toolbar_location": toolbar_location,
"active_scroll": "wheel_zoom",
"x_axis_type": "mercator",
"y_axis_type": "mercator",

  1. Similar to the one above, I would expect the box zoom to lock the aspect ratio. The box zoom tool has a similar argument to accomplish this.BoxZoomTool(match_aspect=True)

automatically adjust colormap_range in geoplot

This is a really nice and useful package, thanks for developing it!

When I plot a map from a geopandas df using plot_bokeh, as in

plot_html=df_merge.plot_bokeh(
figsize=(600, 600),
dropdown=['colA','colB'],
)

and select two columns in the dropdown menu, colA and colB, the colormap_range is automatically chosen to be the max range of both columns. If the ranges of both columns are very different, this only looks good for the column with the largest range, and not for the other. Is it possible to have the colormap_range automatically adjust to show the range of the selected column?

Secondary axis in a lineplot

Hello - I was wondering whether you could add functionality to support a secondary axis in a lineplot?
Right now, the plot method returns the entire figure so there's no straightforward way to specify secondary axis at the pandas level of abstraction.

Docstring

Write Docstrings for plot_bokeh (Pandas & GeoPandas). Good reference are examples of README.md

Hovertool datetime shows as percentage.

Code:

import pandas as pd
import numpy as np

pd.set_option("plotting.backend", "pandas_bokeh")
np.random.seed(42)
df = pd.DataFrame({"Google": np.random.randn(1000)+0.2, 
                   "Apple": np.random.randn(1000)+0.17}, 
                   index=pd.date_range('1/1/2000', periods=1000))
df = df.cumsum()
df = df + 50

df.plot()

Result:
bukeh-example

Relevant versions:
bokeh==2.0.0
pandas==1.0.1
pandas-bokeh==0.4.2

BokehDeprecationWarnings with Bokeh v1.4.0

The latest release of the Bokeh package has deprecated the legend keyword, so the output of all plots now includes the following message:

BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead

AttributeError: 'function' object has no attribute

Hi, I got AttributeError: 'function' object has no attribute 'area' for the Areaplot example and
AttributeError: 'function' object has no attribute 'scatter' for the Iris scatter plot example.

pandas and pandas_bokeh were imported.

Using figsize causes "Javascript Error: invalid bbox"

Running the following code inside jupyterlab 1.0.2 causes an error

import pandas as pd
import pandas_bokeh
pandas_bokeh.output_notebook()

raw_data = {
    'age': [42, 52, 36, 24, 73], 
    'score': [25, 94, 57, 62, 70]
}
df = pd.DataFrame(raw_data, columns = ['age', 'score', ])

df.plot_bokeh(x='age', y='score', title='Age vs Score')
df.plot_bokeh(x='age', y='score', title='Age vs Score', figsize=(9, 5))

First plot works but second plot causes

Javascript Error: invalid bbox {left: 45, top: 29, right: -21, bottom: -40}

Polygon plotting with update 0.4.2

Hi Patrik,

I'm still enjoying your package, thanks again!

I was wondering what happens with updating to 0.4.2. When plotting polygons of european countries, some countries are not plotted anymore with the new version. Did something change with the interaction with GeoDataFrames?

Thanks in advance!

Shapely exception plotting maps

Hello Patrik,

I'm looking at your awesome library. I ran into an issue while testing the states' map examples (not sure if this is a bug, I'm new at all these geo localization stuff):

import requests
import geopandas as gpd
import pandas as pd
import pandas_bokeh
pandas_bokeh.output_file("map_states.html")

#Read in GeoJSON from URL:
df_states = gpd.read_file(r"https://raw.githubusercontent.com/PatrikHlobil/Pandas-Bokeh/master/Documentation/Testdata/states/states.geojson")
df_states.head()

df_states.plot_bokeh(simplify_shapes=10000)

I got the exception:

raise ValueError("No Shapely geometry can be created from null value")

I'm not sure what I'm missing here. It also happens with other examples.

Cheers

Data type not understood

config:
virtualenv:

  • python v.3.8
  • pandas-bokeh v.0.5
  • geopandas 0.7.0

.geojson:
Created via https://geojson-maps.ash.ms/ (with all continents selected)

error:
TypeError: Data type not understood

P.s. It works with exactly same config but pandas-bokeh v.4.3

Pie plot legend_field

Hello again!!!
I'm trying to use pie plot but legend_field is not displaying correctly, I'm using bokeh 1.4.0
image

In other case, I've added layout option to bar plot :) Is this correctly?

p_zone = zone.plot_bokeh.bar( x='Zona', y='Importe', xlabel="Zona", ylabel='Importe', layout=[high_box, low_box], title='Ingreso por zonas', legend_label='Ingreso Zona', vertical_xlabel= True, alpha=0.8, legend = "top_left", panning=False, zooming=False, show_figure=True)

image

Legend issues with pandas-bokeh

Hello - I am experiencing the following issues with pandas_bokeh:

  1. When I plot a large number of timeseries, the legend reaches the maximum number and does not allow scrolling to reveal the rest of the timeseries that have been plotted.
  2. Datetime works on the x-axis but on hover it is interpreted in a weird format.

The following plot demonstrates both problems.

bokeh

Attribute Error in DataFrames

Hello,

I am currently running Numpy v1.15.4, Pandas v0.23.4, Pandas-Bokeh v0.3.1 and find the following error as I run the example code:

import numpy as np
import pandas as pd

np.random.seed(42)
df = pd.DataFrame({"Google": np.random.randn(1000)+0.2,
"Apple": np.random.randn(1000)+0.17},
index=pd.date_range('1/1/2000', periods=1000))
df = df.cumsum()
df = df + 50
df.plot_bokeh(kind="line")

AttributeError: 'FramePlotMethods' object has no attribute '_data'

Checking previous issues I saw this could have been fixed in the latest version, but maybe not yet? The above issue is not present in Series objects. Any help will be appreciated.

Many thanks for this useful package!

Datetime hover tool shows UTC time by default

Hello Team,

I am plotting data on map using plot_bokeh.map(). Everyting seems to be working fine except date time column which is displaying UTC as default . I am using Hoevertool_columns to display the datetime when I hover over the points on map.

Could you please let me know how to fix this issue

Can't make bar chart after groupby.

Thank you very much for making great package. I'm really into it. I'd like to report the bug with the latest version

Environment

pandas 0.23.3
pandas-bokeh 0.1.1
Python 3.6

The program

import numpy as np
import pandas as pd
import pandas_bokeh
pandas_bokeh.output_file("Interactive Plot.html")

x = np.arange(0, 100, 0.1)
df = pd.DataFrame(x)
result = df.groupby(pd.cut(df[0], np.arange(0, 100, 10))).sum()
result.plot_bokeh.bar()

Error

$ python '/tmp/tmp.GaLHNeE1Eg/test.py'
Traceback (most recent call last):
  File "/tmp/tmp.GaLHNeE1Eg/test.py", line 20, in <module>
    result.plot_bokeh.bar()
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/pandas_bokeh/plot.py", line 1845, in bar
    return self(kind="bar", x=x, y=y, **kwds)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/pandas_bokeh/plot.py", line 1659, in __call__
    return plot(self._data, *args, **kwargs)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/pandas_bokeh/plot.py", line 879, in plot
    show(p)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/io/showing.py", line 137, in show
    return _show_with_state(obj, state, browser, new, notebook_handle=notebook_handle)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/io/showing.py", line 175, in _show_with_state
    _show_file_with_state(obj, state, new, controller)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/io/showing.py", line 158, in _show_file_with_state
    filename = save(obj, state=state)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/io/saving.py", line 83, in save
    _save_helper(obj, filename, resources, title, template)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/io/saving.py", line 145, in _save_helper
    html = file_html(obj, resources, title=title, template=template)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/embed/standalone.py", line 281, in file_html
    (docs_json, render_items) = standalone_docs_json_and_render_items(models)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/embed/util.py", line 340, in standalone_docs_json_and_render_items
    docs_json[docid] = doc.to_json()
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/document/document.py", line 781, in to_json
    doc_json = self.to_json_string()
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/document/document.py", line 810, in to_json_string
    return serialize_json(json, indent=indent)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/core/json_encoder.py", line 213, in serialize_json
    return json.dumps(obj, cls=BokehJSONEncoder, allow_nan=False, indent=indent, separators=separators, sort_keys=True, **kwargs)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/core/json_encoder.py", line 135, in default
    return self.transform_python_types(obj)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/site-packages/bokeh/core/json_encoder.py", line 102, in transform_python_types
    return super(BokehJSONEncoder, self).default(obj)
  File "/home/myuser/.pyenv/versions/miniconda3-4.1.11/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'Interval' is not JSON serializable

I think it happens because groupy method makes categorical index.

Bokeh 2.0 is imminent

Just a heads-up that Bokeh 2.0 will be coming out in the next week or so. At a minimum you may want to release packages that versions to <2.0 if they are not already. Whenever you look to update packages for Bokeh 2.0 compat we'd be happy to help over at the Development topic on the Discourse:

https://discourse.bokeh.org/c/development/7

scatter "angle" works with a constant but not with a column

Thank you for your effort, Patrik! I have a challenge with pointing the marker at an angle, but I'm not certain bokeh can do this generally.

My dataframe has ~3400 rows and 3 columns.
df

Out[xxx]:
Xnum Ynum col3
..................

I have already eliminated NaNs:

df=df.dropna(axis=0,how='any')

I have tried this, it produces a graph on /Interactive%20Plot.html, and I can successfully change the angle:

df.plot_bokeh(kind="scatter",x="Xnum",y="Ynum" ,marker="triangle", size=8,angle=0.5,line_width=0.001,figsize=(400, 400) )

When I run this:
df.plot_bokeh(kind="scatter",x="Xnum",y="Ynum" ,marker="triangle", size="col3",angle=0.5,line_width=0.001,figsize=(400, 400) )

I get the error and no plot:

E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: col3 [renderer: GlyphRenderer(id='617da22f-e32c-4004-b8c6-a13be540d385', ...)]

hovertool datetime format

Hello!
I getting stuck with hovertool datetime format, my df dtype is:

history_days.dtypes
Fecha datetime64[ns]
costo int64
dtype: objec

from Pandas-Bokeh:

first_value = np.array(history_days)[0]

first_value
array([Timestamp('2019-12-31 00:00:00'), 1824], dtype=object)

isinstance(first_value, (np.datetime64, datetime.datetime, datetime.date))
False

So, my bar is not showing hovertool with datetime format correctly, What am I missing?

Hovertool String issue/bug

Hi Patrik,

I'm plotting a geo-map using df.plot_bokeh(). I had an issue where the map is not showing when i use the hovertool_string. However, when I use hovertool_columns in which I specify the same columns as in the hovertool_string, it does work.

I found that that my 'size' column contains -inf values. Apparently, these -inf values cause the plot not to show anymore (without a warning or error) when hovertool_string is used.

I still don't understand why the -inf value causes this problem.. But I thought it could be useful for you to know

Multipolygon holes

Thanks for this awesome tool. Is there something specific to make sure holes are also drawn?

image

How to add button to barh?

Hello!!!, I Already have a grid_plot with my data but now I'm trying to update my chart with a callback, Is there a way to add a button to my template? I'm only using barh for now and my update function is already working.

image

Can't install via conda with Python 3.8?

Having created a fresh Python 3.8 conda environment I fail to install pandas-bokeh from conda:

$ conda create -n companies_house python=3.8 pandas scikit-learn matplotlib bokeh jupyter
$ conda activate companies_house
$ conda install -c patrikhlobil pandas-bokeh

Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: / 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed                                                                                                                                                                                                                                        

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - pandas-bokeh -> python[version='>=3.6,<3.7.0a0|>=3.7,<3.8.0a0']

Your python: python=3.8

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

The following specifications were found to be incompatible with your CUDA driver:

  - feature:/linux-64::__cuda==10.1=0
  - feature:|@/linux-64::__cuda==10.1=0

Your installed CUDA driver is: 10.1

Note that strict channel priority may have removed packages required for satisfiability.

If I switch to try $ pip install pandas-bokeh then this succeeds.

If I build a conda environment using the packages noted above but using Python 3.7 then the conda install for your package works (i.e. no cuda errors or other problems).

I think Python 3.8 with conda is the issue, maybe someone else can confirm?

Ignore NaN value's in hovertool

Hi,

I'm new to Bokeh and I'm trying to visualize customers throughout Europe and the corresponding prices that are used for 15 different products. To do this, I mapped the geolocations of every customer and I put the prices of each product in the hovertool.

It's almost works sufficiently, thanks to this great backend. However, i have the following problem:

Each customer only buys 1-8 different products. This means that many prices contain NaN values. In the hovertool this results in '????' for the products that have no price for a specific customer.

In the hovertool, i simply specify a list of column names that should be included. Each column represents a product, which contains a price for each customer (row).

Is there any way i can ignore NaN values in the Hovertool? Or are there more advanced formatting tricks i can use?

Thanks!

Pandas version mismatch

Using latest pandas (1.0.3) and latest pandas-bokeh, I get: ImportError: cannot import name 'BasePlotMethods' from 'pandas.plotting._core' (/usr/local/lib/python3.7/site-packages/pandas/plotting/_core.py). What can be done to overcome that?

Bokeh v1.1.0 deprecation warnings

Using pandas_bokeh v0.1.1 with Bokeh v1.1.0 gives me the following deprecation warnings:

BokehDeprecationWarning: CARTODBPOSITRON was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.CARTODBPOSITRON) instead.
BokehDeprecationWarning: CARTODBPOSITRON_RETINA was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.CARTODBPOSITRON_RETINA) instead.
BokehDeprecationWarning: STAMEN_TERRAIN was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.STAMEN_TERRAIN) instead.
BokehDeprecationWarning: STAMEN_TERRAIN_RETINA was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.STAMEN_TERRAIN_RETINA) instead.
BokehDeprecationWarning: STAMEN_TONER was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.STAMEN_TONER) instead.
BokehDeprecationWarning: STAMEN_TONER_BACKGROUND was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.STAMEN_TONER_BACKGROUND) instead.
BokehDeprecationWarning: STAMEN_TONER_LABELS was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.STAMEN_TONER_LABELS) instead.
BokehDeprecationWarning: CARTODBPOSITRON was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.CARTODBPOSITRON) instead.
BokehDeprecationWarning: CARTODBPOSITRON_RETINA was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.CARTODBPOSITRON_RETINA) instead.
BokehDeprecationWarning: STAMEN_TERRAIN was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.STAMEN_TERRAIN) instead.
BokehDeprecationWarning: STAMEN_TERRAIN_RETINA was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.STAMEN_TERRAIN_RETINA) instead.
BokehDeprecationWarning: STAMEN_TONER was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.STAMEN_TONER) instead.
BokehDeprecationWarning: STAMEN_TONER_BACKGROUND was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.STAMEN_TONER_BACKGROUND) instead.
BokehDeprecationWarning: STAMEN_TONER_LABELS was deprecated in Bokeh 1.1.0 and will be removed, use get_provider(Vendors.STAMEN_TONER_LABELS) instead.

Styling

Patrik,

First let me congratulate you on an amazing piece of software. I appreciate all of your hard work! My comments below pertain to histograms.

  • It would be great if the user had the ability to change the numbers from scientific to regular numbers on the x axis.
  • It would be good if you could use actual text of your choosing on the different axes. Like vertical_ylabel="lbs"
  • Lets say your pandas frame has two columns that are scaled quite a bit differently. It would be wonderful if you could have both data frames overlayed on the same graph with two x axes. Stacked with one above the other (different that overlain). It would be good if the user could pick on the variable they want to use.

Thanks again.

No longer compatible with pandas >= 0.25.0

The most recently-released version of pandas no longer works correctly with Pandas-Bokeh, as the plotting "hooks" in pandas <= 0.24.2 no longer exist and have been replaced with a new plotting backend option described in pandas-dev/pandas#26753. Unfortunately I'm not familiar enough with pandas' internals to write a patch to adapt the existing interface to work with pandas >= 0.25.0.

Issue with Map Plot

When I try to run the Mapplot example, I get the following error when I try to use plot_bokeh.map:

AttributeError: 'function' object has no attribute 'map'

The whole code is as follows:

import pandas as pd
import pandas_bokeh
pandas_bokeh.output_notebook()

df_mapplot = pd.read_csv(r"https://raw.githubusercontent.com/PatrikHlobil/Pandas-Bokeh/master/Documentation/Testdata/populated%20places/populated_places.csv")

df_mapplot["size"] = df_mapplot["pop_max"] / 1000000
df_mapplot.plot_bokeh.map(
    x="longitude",
    y="latitude",
    hovertool_string="""<h2> @{name} </h2> 
    
                        <h3> Population: @{pop_max} </h3>""",
    tile_provider="STAMEN_TERRAIN_RETINA",
    size="size", 
    figsize=(900, 600),
    title="World cities with more than 1.000.000 inhabitants")

FutureWarning when using GeoPlots with GeoDataFrame

Hi Patrick,

When using geoplots this future warning comes up.

FutureWarning: '+init=:' syntax is deprecated. ':' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
projstring = _prepare_from_string(" ".join((projstring, projkwargs)))

I believe its happening from

inProj = Proj(init="epsg:4326")
outProj = Proj(init="epsg:3857")

in geoplot.py code
Maybe just changing it to "espg:4326" form should work.

Problem plotting data without first saving to csv and reloading csv

Hi,

I am using the latest version of the library in a JupyterLab (1.1.4) environment.

The problem I have that I want to plot a rather simple dataset I retrieve from a url. The data is retrieved and converted to a pandas DataFrame without problems. If I then try to plot the data the library simply turns out error "0".

The full standalone code is below. Notice that nearly at the end I save the pandas dataframe to a CSV, then directly read that CSV back into another pandas dataframe and I can plot the data. So plotting df_a works as planned, trying to plot df results in an error.

regards
Cor

import requests
import csv
import io
import pandas as pd
import pandas_bokeh
pandas_bokeh.output_notebook()

url = 'http://www.seismicportal.eu/fdsnws/event/1/query?limit=100&minmag=4.5&minlat=34&maxlat=42&minlon=26&maxlon=46&format=text'
r = requests.get(url)
content = r.content.decode('iso-8859-1')
lines=[]
for line in csv.reader(content.splitlines(),delimiter='\n'): #start by splitting the response by linebreaks
    lines+=line
df = pd.DataFrame([sub.split("|") for sub in lines])
    
# Retrieve HTTP meta-data
# print(r.status_code)
# print(r.headers['content-type'])
# print(r.encoding)

new_header = df.iloc[0] #grab the first row for the header
df = df[1:] #take the data less the header row
df.columns = new_header
df.columns=df.columns.str.strip() #remove any trailing/starting spaces from columnnames
df.Longitude=df.Longitude.astype(float)
df.Latitude=df.Latitude.astype(float)
df.Magnitude=df.Magnitude.astype(float)
df.to_csv('savequakes.csv')
dfa = pd.read_csv('savequakes.csv')

dfa['size']=dfa.Magnitude*5
dfa.plot_bokeh.map(
    x="Longitude",
    y="Latitude",
    category='Magnitude',
    colormap='Magma',
    line_color='black',
    hovertool_string="<h2> @{Time} </h2> <h3> Magnitude: @{Magnitude} </h3>",
    tile_provider='CARTODBPOSITRON',
    size="size",
    figsize=(1200, 800),
    title="earthquakes")

How to use formatter with custom hovertool_string.

I'd like to use custom Datetime format for hovertool_string.But, it seems there is no way to define formatter from outside. Could you tell me how to use it?

my_hover.tooltips = hovertool_string

import pandas_bokeh
import numpy as np
import pandas as pd
pandas_bokeh.output_file('sample.html')

rng = pd.date_range('2015-02-24', periods=5, freq='T')
df = pd.DataFrame({'Date': rng, 'Val': np.random.randn(len(rng))})
df.index = df['Date']
del df['Date']
df.plot_bokeh(hovertool_string='@__x__values_original{%F}')

Multiple layers in a map

Hi,

Thanks for providing this library, it makes createing graphs/plots from dataframes a lot easier !!

I am working in jupyterlab.

I am trying to display data from two shapefiles (one with lines, other with polygons) in a single plot(code below), this works fine but produces two different plots. I would like to plot these into a single plot. Normally (I have this code in "normal" bokeh) I would create a figure (eg p=figure(...), add my plots to it (p.multi_line(...) and finish with show(p). Did I miss anything in the documentation ?

kind regards,
Cor

import pandas as pd
from shapely.geometry import Point
from geopandas import GeoDataFrame
import pandas_bokeh as pdb
from bokeh.plotting import figure
lijnen= gpd.read_file('lines.shp',crs={'init': 'epsg:3857'})
vlakken=gpd.read_file('vlakken.shp',crs={'init': 'epsg:3857'})
lijnen.crs={'init': 'epsg:3857'}
vlakken.crs={'init': 'epsg:3857'}
l=lijnen.plot_bokeh()
v=vlakken.plot_bokeh()'

T

RuntimeError: Models must be owned by only a single document, CDSView(id='1142', ...) is already in a doc

Hi!

I have a problem that is likely due to interaction with Bokeh, but it occurs only when using pandas_bokeh plots and not Bokeh plots directly.

When trying to make a dashboard with pandas_bokeh with layout or plot_grid, I get the following error:

Traceback (most recent call last):
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/app/Influenza/src/main/python/main.py", line 370, in on_click_check
    bokehPlots.bokehPlots(self.data_demo, self.data_case)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/app/Influenza/src/main/python/bokehPlots.py", line 162, in bokehPlots
    pandas_bokeh.plot_grid([[p_noso]])
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/pandas_bokeh/base.py", line 53, in plot_grid
    show(layout)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/pandas_bokeh/base.py", line 134, in show
    bokeh.plotting.show(obj, browser, new, notebook_handle, notebook_url)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/io/showing.py", line 145, in show
    return _show_with_state(obj, state, browser, new, notebook_handle=notebook_handle)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/io/showing.py", line 183, in _show_with_state
    _show_file_with_state(obj, state, new, controller)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/io/showing.py", line 166, in _show_file_with_state
    filename = save(obj, state=state)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/io/saving.py", line 86, in save
    _save_helper(obj, filename, resources, title, template)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/io/saving.py", line 148, in _save_helper
    html = file_html(obj, resources, title=title, template=template)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/embed/standalone.py", line 297, in file_html
    with OutputDocumentFor(models, apply_theme=theme, always_new=_always_new) as doc:
  File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/embed/util.py", line 138, in OutputDocumentFor
    doc.add_root(model)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/document/document.py", line 304, in add_root
    self._pop_all_models_freeze()
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/document/document.py", line 1019, in _pop_all_models_freeze
    self._recompute_all_models()
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/document/document.py", line 1042, in _recompute_all_models
    a._attach_document(self)
  File "/mnt/c/Users/thiabaud/Documents/IOGH_Influenza/DataAnalysis/Scripts/Python/pyqt5_venv/lib/python3.6/site-packages/bokeh/model.py", line 714, in _attach_document
    raise RuntimeError("Models must be owned by only a single document, %r is already in a doc" % (self))
RuntimeError: Models must be owned by only a single document, CDSView(id='1142', ...) is already in a doc

When looking for a solution, Bokeh's documentation and overall Stackoverflow answers say that it's likely to be either an object being used several time (which it isn't), or the source dataframe must not be used several time - but I tried using different dataframes for each plot without any luck. Creating a layout or using plot_grid result in the same error.

I'm running bokeh 1.3.4 and pandas_bokeh 0.3
As I previously mentioned, the error occurs only when I use plots created with pandas_bokeh, the bokeh alone plot is properly dashboarding on its own with plot_grid.

vertical line in HTML charts

Guys, this is how I'm drawing my chart in html with blot_bokeh:

`df = pd.DataFrame({ headers[p1]: values[p1],
headers[p1]+"_MK" : cur2mk[headers[p1]],
headers[p2]: values[p2],
headers[p2]+"_MK" : cur2mk[headers[p2]],
"":zero })

html = df.plot_bokeh(kind="line",colormap=["lightgreen","darkgreen","orange", "brown", "grey"], title=chart_title, figsize=(1400, 450), show_figure=False,return_html=True,legend=False)
`

How can I add a vertical line to this plot and have it working in HTML? I have the tuple values for start_date and end_date as well, but ideally I'd prefer to have relative shifts driving it.

Thanks in advance!

Add downstream tests to Bokeh

Please consider defining a subset of tests that specifically exercise your usage of Bokeh, and add them to to downstream tests we run by making a PR to edit these two files:

https://github.com/bokeh/bokeh/blob/master/scripts/ci/install.downstream
https://github.com/bokeh/bokeh/blob/master/scripts/ci/test.downstream

The downstream tests are only indicative, i.e. we never fail a build based on their result (since the problem may not be on our end end we have no control in that case) but they can be a useful leading indicator of potential compatibility problems.

Plotting LineString

Hi,

I think there's a bug when setting a geopandas LineString column as the geometry column, and running gdf.plot_bokeh()
if the column name isn't 'geometry' we get an error 'geometry not in index'
only after i changes the column name to geometry I got the plot
actually I think this happens not just for LineString also for 'regular' Point..
gdf['return_point'] = [Point(xy) for xy in zip(gdf["return_lng"],gdf["return_lat"])] gdf['take_point'] = [Point(xy) for xy in zip(gdf["take_lng"],gdf["take_lat"])] gdf['line'] = [LineString(ab) for ab in zip (gdf["take_point"], gdf["return_point"])] gdf.set_geometry('line',inplace=True) gdf.crs = {'init' :'epsg:4326'} #gdf.plot_bokeh() test= gpd.GeoDataFrame(gdf,geometry='line') test.crs = {'init' :'epsg:4326'} test = test.rename(columns={'line': 'geometry'}).set_geometry('geometry') test.plot_bokeh()

plot() method on pd.Series objects raises AttributeError

With Pandas-Bokeh 0.3 and Pandas 0.25.0 in a Jupyter notebook, the following code produces an AttributeError:

import pandas as pd
pd.set_option('plotting.backend', 'pandas_bokeh')
pd.plotting.output_notebook()

series = pd.Series(np.random.randn(10000))
series.plot(kind='hist')

The full error message is:

AttributeError: unexpected attribute 'reuse_plot' to Quad, possible attributes are bottom, fill_alpha, fill_color, hatch_alpha, hatch_color, hatch_extra, hatch_pattern, hatch_scale, hatch_weight, js_event_callbacks, js_property_callbacks, left, line_alpha, line_cap, line_color, line_dash, line_dash_offset, line_join, line_width, name, right, subscribed_events, tags or top

Using series.plot_bokeh(kind='hist') works fine, however.

Adding a dummy reuse_plot=True argument to the plot method in pandas_bokeh/plot.py around line 154 appears to fix the problem.

https://github.com/PatrikHlobil/Pandas-Bokeh/blob/master/pandas_bokeh/plot.py#L154

ValueError: Only LayoutDOM items can be inserted into a grid

Hi PatrikHlobil,

Thank you for the nice article on Pandas-Bokeh. However, when I try to create a grid am getting this error "ValueError: Only LayoutDOM items can be inserted into a grid". Kindly help me out. Attached is my code snippet.

Thanks,,
Victor.

import pandas as pd
import pandas_bokeh
import numpy as np
from bokeh.layouts import row, column
import sqlalchemy as sql
from bokeh.models import Button, ColumnDataSource, Range1d, Toolbar, ToolbarBox
from bokeh.models.layouts import LayoutDOM, Box, Row, Column, GridBox, Spacer, WidgetBox
from bokeh.models.tools import HoverTool, WheelZoomTool, PanTool, CrosshairTool, LassoSelectTool
from bokeh.layouts import layout, gridplot
from bokeh.plotting import curdoc, figure

pandas_bokeh.output_file("kisovi.html")

Read in MySQL Data

connect_string = 'mysql://root:oracle@localhost/zabbix'
sql_engine = sql.create_engine(connect_string)

df_now = pd.read_sql("""
select hosts.host as Hostname, key_ as key_value, max(history.value) as "Max CPU Load",avg(history.value) as "Average CPU Load" ,
min(history.value) as "Min CPU Load" from history, items, hosts where hosts.hostid=items.hostid and hosts.host NOT LIKE '%%Template%%' AND host NOT LIKE '%%{%%' and items.key_
like 'system.cpu.load[percpu,avg1]' and items.value_type=0 and history.itemid=items.itemid group by items.itemid, key_value order by hosts.host asc;
"""
, sql_engine)

df_now = pd.DataFrame(df_now, columns=['Hostname','Max CPU Load', 'Average CPU Load', 'Min CPU Load'])
df_now = pd.DataFrame(df_now).set_index("Hostname")
df_now.plot_bokeh(
kind="bar",
ylabel="CPU Load",
title="Current CPU Load",
show_figure=True,
return_html=True,
alpha=0.6)
p5=df_now

df_5 = pd.read_sql("""
select hosts.host as Hostname, key_ as key_value, max(history.value) as "Max CPU Load",avg(history.value) as "Average CPU Load" ,
min(history.value) as "Min CPU Load" from history, items, hosts where hosts.hostid=items.hostid and hosts.host NOT LIKE '%%Template%%' AND host NOT LIKE '%%{%%' and items.key_
like 'system.cpu.load[percpu,avg5]' and items.value_type=0 and history.itemid=items.itemid group by items.itemid, key_value order by hosts.host asc;
"""
, sql_engine)

df_5 = pd.DataFrame(df_5, columns=['Hostname','Max CPU Load', 'Average CPU Load', 'Min CPU Load'])
df_5 = pd.DataFrame(df_5).set_index("Hostname")
df_5.plot_bokeh(
kind="bar",
ylabel="CPU Load",
title="5 Mins CPU Load",
show_figure=True,
return_html=True,
alpha=0.6)
p6=df_5

df_15 = pd.read_sql("""
select hosts.host as Hostname, key_ as key_value, max(history.value) as "Max CPU Load",avg(history.value) as "Average CPU Load" ,
min(history.value) as "Min CPU Load" from history, items, hosts where hosts.hostid=items.hostid and hosts.host NOT LIKE '%%Template%%' AND host NOT LIKE '%%{%%' and items.key_
like 'system.cpu.load[percpu,avg5]' and items.value_type=0 and history.itemid=items.itemid group by items.itemid, key_value order by hosts.host asc;
"""
, sql_engine)

df_15 = pd.DataFrame(df_15, columns=['Hostname','Max CPU Load', 'Average CPU Load', 'Min CPU Load'])
df_15 = pd.DataFrame(df_15).set_index("Hostname")
df_15.plot_bokeh(
kind="bar",
ylabel="CPU Load",
title="15 Mins CPU Load",
show_figure=True,
return_html=True,
alpha=0.6)
p7=df_15

#row([plot_1, plot_2])
#row(children=[widget_box_1, plot_1], sizing_mode='stretch_both')

#layout=row([p5, p6, p7], merge_tools=True)

#row(children=[p5, p6, p7], sizing_mode='stretch_both')

#column([p5, p6, p7])
#column(children=[widget_1, p5], sizing_mode='stretch_both')

#curdoc().add_root(layout)

#gridplot([[p5, p6], [p7]])
#gridplot([p5, p6, p7], ncols=2, plot_width=200, plot_height=100)
#pandas_bokeh.plot_grid(

children=[[p5, p6, p7]],

toolbar_location='right',

sizing_mode='stretch_both',

toolbar_options=dict(logo='gray')

#)

pandas_bokeh.plot_grid([p5, p6, p7], plot_width=450)

#pandas_bokeh.plot_grid()

Lineplot Rangetool broken?

Hi,
when I execute your sample code in Jupyter:

ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD'))
df = df.cumsum()
df.plot_bokeh(rangetool=True)

The following Error appears:


AttributeError Traceback (most recent call last)
in
3 df = df.cumsum()
4
----> 5 df.plot_bokeh(rangetool=True)

~/anaconda3/envs/E1lib/python3.7/site-packages/pandas_bokeh/plot.py in call(self, *args, **kwargs)
1735
1736 def call(self, *args, **kwargs):
-> 1737 return plot(self.df, *args, **kwargs)
1738
1739 @Property

~/anaconda3/envs/E1/lib/python3.7/site-packages/pandas_bokeh/plot.py in plot(df_in, x, y, kind, figsize, use_index, title, legend, logx, logy, xlabel, ylabel, xticks, yticks, xlim, ylim, fontsize, color, colormap, category, histogram_type, stacked, weights, bins, normed, cumulative, show_average, plot_data_points, plot_data_points_size, number_format, disable_scientific_axes, show_figure, return_html, panning, zooming, toolbar_location, hovertool, hovertool_string, vertical_xlabel, webgl, **kwargs)
477 hovertool_string,
478 number_format,
--> 479 **kwargs
480 )
481

~/anaconda3/envs/E1/lib/python3.7/site-packages/pandas_bokeh/plot.py in lineplot(p, source, data_cols, colormap, hovertool, xlabelname, x_axis_type, plot_data_points, plot_data_points_size, hovertool_string, number_format, **kwargs)
1013 hovertool_string=hovertool_string,
1014 number_format=number_format,
-> 1015 **kwargs
1016 )
1017

~/anaconda3/envs/E1/lib/python3.7/site-packages/pandas_bokeh/plot.py in _base_lineplot(linetype, p, source, data_cols, colormap, hovertool, xlabelname, x_axis_type, plot_data_points, plot_data_points_size, hovertool_string, number_format, **kwargs)
951 source=source,
952 color=color,
--> 953 **kwargs
954 )
955

fakesource in line(self, x, y, **kwargs)

~/anaconda3/envs/E1lib/python3.7/site-packages/bokeh/plotting/helpers.py in func(self, **kwargs)
855 mglyph_ca = None
856
--> 857 glyph = _make_glyph(glyphclass, kwargs, glyph_ca)
858 nsglyph = _make_glyph(glyphclass, kwargs, nsglyph_ca)
859 sglyph = _make_glyph(glyphclass, kwargs, sglyph_ca)

~/anaconda3/envs/E1/lib/python3.7/site-packages/bokeh/plotting/helpers.py in _make_glyph(glyphclass, kws, extra)
396 kws = kws.copy()
397 kws.update(extra)
--> 398 return glyphclass(**kws)
399
400

~/anaconda3/envs/E1/lib/python3.7/site-packages/bokeh/model.py in init(self, **kwargs)
305 kwargs.pop("id", None)
306
--> 307 super(Model, self).init(**kwargs)
308 default_theme.apply_to_model(self)
309

~/anaconda3/envs/E1/lib/python3.7/site-packages/bokeh/core/has_props.py in init(self, **properties)
251
252 for name, value in properties.items():
--> 253 setattr(self, name, value)
254
255 def setattr(self, name, value):

~/anaconda3/envs/E1/lib/python3.7/site-packages/bokeh/core/has_props.py in setattr(self, name, value)
286
287 raise AttributeError("unexpected attribute '%s' to %s, %s attributes are %s" %
--> 288 (name, self.class.name, text, nice_join(matches)))
289
290 def str(self):

AttributeError: unexpected attribute 'rangetool' to Line, possible attributes are

js_event_callbacks, js_property_callbacks, line_alpha, line_cap, line_color, line_dash, line_dash_offset, line_join, line_width, name, subscribed_events, tags, x or y

Bokeh 1.1 problem with overlay layers in maps

With Bokeh 1.1, overlaying two layers with geopandas results in only the last layer shown (@heuvel). Example:

import pandas as pd
import geopandas as gpd
import pandas_bokeh

from bokeh.plotting import figure
from bokeh.io import output_notebook

from shapely.geometry import Point

output_notebook()

point_a_df = pd.DataFrame([['a', Point(4.96548,52.49110)]], columns=['id','geometry'])
point_a_gdf = gpd.GeoDataFrame(point_a_df, geometry='geometry')
point_a_gdf.crs = {'init':'epsg:4326'}

point_b_df = pd.DataFrame([['b', Point(4.63045,52.38150)]], columns=['id','geometry'])
point_b_gdf = gpd.GeoDataFrame(point_b_df, geometry='geometry')
point_b_gdf.crs = {'init':'epsg:4326'}

p = figure()
point_a_gdf.plot_bokeh(figure=p, show_figure=False)
point_b_gdf.plot_bokeh(figure=p, show_figure=True)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.