Can I bold invididual elements in y_range of a bokeh chart? - text

I would like to bold some of the values in my y_range but not others.
I have tried using p.yaxis.major_label_text_font_style = 'bold'. This bolds everything. I have also tried setting it equal to a column in a ColumnDataSource, but major_label_text_font_style does not accept that as an input.
# Orient y axis labels
p.yaxis.major_label_text_font_size = '18pt'
p.yaxis[0].major_label_text_font_style = 'bold'
p.yaxis.major_label_text_font = "calibri"
I would like some of the text in my y_range to be bold, but not all of the text

As of Bokeh 1.1 there is no built-in way to accomplish this. [1] The main reason is that, in general, tick labels and locations can be chosen dynamically, as a result of panning and zooming. There is no guarantee a tick you want to treat differently will actually be labeled or on the screen at all. I.e. it's not useful to say "make the third tick bold" if you have no idea of knowing or controlling what the third tick will be.
However, it might be possible to do something different in the case of categorical ticks, which are normally always all displayed, and so known up-front. I'd encourage you to file a GitHub feature request issue to discuss it.
[1] One could potentially create a custom extension Axis subclass to do this, but that would be non-trvial work, as Axis is one of the most complicated BokehJS objects.

Related

Italicize and color legend manually for different graphs using same labels and colors

I am trying to create multiple graphs that share the same legend.
I have found many ways to combine multiple graphs and it seems that ggarrange has the ability to create one shared legend for all that is supposed to be unique.
However I am having some problems when graphing since a few of the graphs do not have the same phyla (what defines the legend colors) present, but I would like them all to be the same colors throughout all of the graphs so the combined legend will have the correct colors.
For just one graph I would assign a color to the label manually like below
labs<-c("Arthropoda"="#FF66CC"
,"Cercozoa"="#FF6000")
and plot with the addition of scale_fill_manual(values=labs) and this seems to work
then I modified it so I could have portions of them italicized.
labsPhylum <-c('expression(paste(italic("Arthropoda")))'="#CC0000"
,'expression(paste(italic("Cercozoa")))'= "#FF6000"
,'expression (paste("unknown", ~italic("Eukaryota")))'= "#990000")`
However when I create a plot using ggplot and scale_color_manual() using the labsPhylum that I think should be italicized and colored I plot an empty graph with this warning so there is something vital I am not understanding here.
ggplot(data=sigtab_dil, aes(x=Species, y=log2FoldChange, color=Phylum))+
geom_point(size=2) +
scale_color_manual(values=labsPhylum)
Warning message:
Removed 9 rows containing missing values (geom_point).
Could someone please help me figure out where I am going wrong?
Thank you
Answered my own question
I realized I had to make separate vectors for breaks, labels, and values rather than combining them.
In short
colsPhylum <-c("Arthropoda"="#CC0000"
,"Cercozoa"= "#FF6000"
,"Chlorophyta"= "#CC9900"
labsPhylum <-c(expression(paste(italic("Arthropoda")))
,expression(paste(italic("Cercozoa")))
,expression(paste(italic("Chlorophyta ")))
breaksPhylum <-c("Arthropoda", "Cercozoa","Chlorophyta", "Choanozoa"
,"Ciliophora"
,"Cryptista"

Matplotlib using text instead of marker BUT can't be the best way to do it?

I would just like to make sure I am on the right track here as this seems to be pretty cumbersome for Matplotlib. I want to use a label as a marker on a plot and have it working to some degree. It uses mathtext BUT I wonder if there isn't another way to do it? Here is the code.
import matplotlib.pyplot as plt
x = []
y = []
symbol = "AAPL"
x = range(5)
y = [5,10,12,15,11]
plt.plot(x,y,lw=2.5,color='r',linestyle='solid',marker=r"$ {} $".format(symbol),markersize=25)
plt.show()
I am not 100% sure what you want, but below I have listed a couple of options that I am aware of for putting text into plots at specific locations (essentially what a marker is).
1) you can uses text/characters as markers through unicode. This is done by adding the unicode value within mathtext characters. E.g. take your example code; you can make the marker a unicode character by adding a 'u' before the string (unneeded in python 3) and then a '\u' and a 4 digit number. this will produce a unicode marker. Not all will work, as it depends on whether your system's font supports it. You can find a long list of them here: http://unicode-table.com/en/#latin-extended-a
plt.plot(x,y,lw=2.5,color='r',linestyle='solid',marker=u'$\u2609$',markersize=25)
\u2609 will produce a 'sun', i.e. a circle with a dot in its centre.
2) plt.text(...) using this function you can add text of your choice to the coordinate you specify.
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.text
I believe the coordinate will correspond to the bottom left corner of the text box, but you can play around with it to make absolutely sure if you want. E.g.
plt.text(x,y,'string',fontsize=18)
However, this must be done on individual points and will not plot a line over the data; it does not work like 'plot' although you could always brute force a line over the top with a subsequent line plot. This method is more of a pain and hardly optimal but it will do the job and is quite flecible if you want a string for a marker.

d3.js. How to organize bubbles along the line without overlaps?

I want to make such kind of bubble chart:
But only i can do is here - http://jsfiddle.net/zeleniy/h646uopc/6/.
jsfiddle code mock
How i can move them apart to escape overlapping. I understand that in some cases bubbles will be shifted along the x axis because of chart height limit. But in any case i do not know how to do it? And i am not sure that want to use force layout to scatter bubbles. I want do draw it at once.
Finally i do it - http://zeleniy.me/stretched-bubble-chart.html.
You should use force layout with specific gravity implementation. Read this article for details - http://vallandingham.me/building_a_bubble_cloud.html

How do I put tick labels inside of a line graph in Flot

I essentially want to have the tick labels sitting inside the graph in their own column. Similar to how Campaign Monitor graphs are. But I can't find a way to do this. Is it possible?
In current versions of flot, the only thing you can control about the ticks is the contents and the label class (all ticks have the class "tickLabel").
I think with those two abilities, you cannot do what you're looking for.
Check out this flot bug for some code modifications that might get you to what you want: http://code.google.com/p/flot/issues/detail?id=191
How is this question different than this one?
jQuery Flot data/axis labels on top of graph
For that one, someone suggests negative labelMargins

Centering fonts in VB6

How do you determine the length of a string of text in Arial Bold font, and then center it in VB6?
We are not using a "label" or "picture box" to print the text to the screen. We are sizing the text on the fly, and allowing the user to scale the size of our application to their liking. We write the text to screen using code.
One way is to have a hidden picture box and setup the font specs of that picture box the way you want.
Then use the TextHeight and TextWidth methods of the PictureBox to take your measurements. The Units will be in whatever scalemode the Picture Box is set to.
If you are printing directly to the printer or form then just set your font FIRST then take your measurements.
To center it
MyText = "Hello World"
<displayarea>.FontName = "Arial"
<displayarea>.FontSize = 14
<displayarea>.FontBold = True
TextWidth = <displayarea>.TextWidth(MyText)
TextLeftCoordinate = <displayarea>.ScaleLeft+<displayarea>.ScaleWidth/2-TextWidth/2
<displayarea>.CurrentX = TextLeftCoordinate
<displayarea>.Print MyText
Substitute displayarea with whatever object you are using.
Based on your updated answer note that the hidden picture box suggestion isn't used to print. It is only get text measurement. However you are printing directly to the form so you just need to use the code example above.
I can't remember the specifics (it's been about 3 years since I last used VB 6), but there's a method on Form called something like "MeasureString". It takes the string, and measures it according to the font settings of the form.
Also, here's a comment posted by Jason Lepack in case I've misunderstood and over-complicated your requirements:
"Labels usually have an alignment property. If you set it to align to center then, regardless of the font face it should center in the label".
There are Win32 GDI functions you can invoke: see for example GetTextExtentPoint32 at http://msdn.microsoft.com/en-us/library/ms534223(VS.85).aspx
Your best option may be Form.TextWidth, which appears to return the width of a string in twips. I've just taken this approach in order to dynamically size a button based on the length of the label that needs to appear inside it.
There is also a corresponding function called Form.TextHeight which would allow you to do the same thing in the vertical dimension.
Make sure that you set the Font property of the form to match the Font property of the control you're intending to measure the text for, otherwise you'll get incorrect results.
Read more at http://msdn.microsoft.com/en-us/library/aa267168(VS.60).aspx

Resources