How to make scatter plots with log scale on both axes

Hi everybody.

I am trying to analyze flow cytometry data with PyDev in Eclipse and the plotting aspect is driving me crazy.

This was done with p = sample.plot_scatter(‘BUV395-A’, ‘FL-A’, source=‘raw’)

I need the X and y axis both on log scale but trying
p = figure(y_axis_type=“log” ,x_axis_type=“log”, x_range=(0,270000), y_range=(0,270000))
or any similar thing produces a validation check missing renderers error.

Change range so it does not start with 0 since you will have log scale, e.g.
x_range = (0.001, 270000)
y_range = (0.001, 270000)

1 Like

Hello rdzudzar.

Thank you for pointing that out.

I changed it fro 0 to 1 now get a blank plot with log scale axes instead of nothing, but still have this error:
WARNING:bokeh.core.validation.check:W-1000 (MISSING_RENDERERS): Plot has no renderers:

I am using the webgl backend.
Could that be a problem?

They means you haven’t actually added any glyphs e.g. circle. Usually that’s a mistake so we we print a warning, but if you intend to have an empty plot with no glyphs you can just ignore if.

Hi Bryan.

My goal is not to have an empty plot, but rather to have the data shown in my original post plotted on log scale.

This syntax came from FlowKit, and was used to generate the plot I showed:
p = sample.plot_scatter(‘BUV395-A’, ‘FL-A’, source=‘raw’)

It uses bokeh and works fine.
You can see the functionality where it colored the points according to density of data at that location, so it is not just circles of a single color.

This is what it should look like and was plotted using R:

This is the tutorial I have been following, but substituted real data instead of the sample data:
https://github.com/whitews/FlowKit/blob/master/examples/flowkit-tutorial.ipynb

Your question is really unclear. Are you saying you used something called plot_scatter to generate Bokeh output? If so, plot_scatter is not a Bokeh API (e.g. I don’t know anything about it out what it is or is supposed to do). If it is part of some other package or tool, you would need to ask for help from the developers of that package, it’s not on-topic for this forum.

it is not just circles of a single color.

Bokeh can plot circles of any different sizes or colors but the Bokeh API for that is .circle (or .scatter) If you need help using .circle or .scatter that is something that is on-topic for this forum. But the first information you need to provide is the code for what you’ve already tried. There are lots of options and examples of scatters with varying colors in the docs and example repo.

Hello Bryan.
Thank you for taking the time to help me.

My apologies for being unclear, but I am completely new to this and got confused by the many levels of packaging.

I understand now that sample.plot_scatter a composite function that is calling bokeh and does not support axis rescaling, so let me rephrase the question in a way that you hopefully can answer by explaining what I am trying to do.

The flow cytometer simultaneously measures fluorescence in multiple channels and generates an array with the channels as columns and values for each data point as rows. The R plot above shows the data of 2 chanels plotted against each other on a logarithmic scale.

I want to do that in python with bokeh, so the question amounts to:
“How to I make a 2D scatter plot from a matrix or data frame where the axes are on a log scale”.

The coloring by density is not really mandatory, but would be nice.

@AlexanderWMacFarlane

Here’s a very basic illustrative example.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
"""
import numpy as np

from bokeh.plotting import figure
from bokeh.io import show

from bokeh.models import ColumnDataSource, LinearColorMapper
from bokeh.palettes import viridis

# data
n = 1001
ch1 = np.random.random(n) * 1000.0
ch2 = np.random.random(n) * 1000.0
rho = np.random.random(n)

data = dict(ch1=ch1, ch2=ch2, rho=rho)
source = ColumnDataSource(data=data)

# density colormap
mapper = LinearColorMapper(palette=viridis(256), low=rho.min(), high=rho.max())

p = figure(width=400, height=400, x_axis_type='log', y_axis_type='log')
r = p.circle(x='ch1', y='ch2', source=source, size=10,
             fill_color={'field': 'rho', 'transform': mapper},
             line_color=None)

show(p)
2 Likes

Thank you _im
(International Master?)

I will use that as a starting point and should be able to figure it out.

bokeh_plot (1)