How can the font (size, boldness, name) be changed for a python-pptx graph - report

This question is for whoever is struggling to make sense of the python-pptx docs and has not found a way to directly change the fonts ( of the x-axis, y-axis labels and etc) of their python -pptx chart objects
I will be answering my own question

Once you've created a graph you can change its attributes as follows. I only changed the font size but you can change boldness,color, type...
chart = slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data)
chart.chart_part.chart.font.size = Pt(11)
the .chart_part has many useful controls for python -pptx chart layout

Related

How can I make the internal node representation smaller in the plotting function of the partykit/glmertree package in R?

I am working with the glmertree package in R, which is an extension of the partykit package. I am trying to plot a model using the glmertree plotting function, which simply extends the partykit plotting function. I would like to make the circles for the internal nodes smaller in my plot so that they do not all overlap. I have extensively researched the ip_args (inner panel args) option for a party kit plot, but all I have managed to do is change the font size or the font color or what is printed in the internal node- I cannot change the circle size. Can anyone help with this?
Default plot, made with the code
plot(glmr_reasonable)
Using the code:
ip_args=list(abbreviate=FALSE, pval=FALSE, gp=gpar(cex=0.5, col="red", pin=c(0.25, 0.25)))
plot(glmr_reasonable, ip_args=ip_args)
I was able to make the following changes:
New plot
However, I don't want red text and tiny font, I want smaller circles. Does anyone know how to help?
Thanks!
The node_inner() panel function currently determines how large the label for the longest splitting variable name is and chooses the size of the ellipse correspondingly. However, due to a bug (that I just fixed on R-Forge) the gpar settings within the ip_args had not been processed correctly.
If you have one (or a few) variable name(s) that is/are quite long like STABLE_RESIDENCE then all ellipses become larger. (It would just look awkward to make this only larger for some nodes.) To save space you can either abbreviate the text or decrease the font size:
By setting ip_args = list(abbreviate = 10), say, only those variable names that are longer than 10 would get abbreviated automatically, thus making all ellipses smaller.
By decreasing the fontsize throughout the entire plot you will also make the ellipses smaller, e.g., plot(..., gp = gpar(fontsize = 9)).
Decreasing the fontsize just locally in the inner nodes (but not the rest of the tree) will also make the ellipses smaller, e.g., ip_args = list(gp = gpar(fontsize = 9)).
The last point did not work correctly up to now but I have just committed a fix to R-Forge. (To install this you currently have to check out and install by hand because R-Forge's auto-builder currently seems to hang...)

Find out Bokeh Figure Attributes

If I have the following figure, where the rect has a colormapper fill_color, is there some way to find out what exactly the colors are?
p = figure(toolbar_location=None,
x_range = hm_data['Models'],
y_range=[metric],
plot_width=400, plot_height=75)]
p.rect(x = 'Models' , y = 'Metrics',
width=1, height=1,
fill_color={'field': 'Values', 'transform': mapper},
line_color= None,
source = source)
I assumed I could call something like p.rect.fill_color, but I haven't been able to find anything. I want to be able to use the list of colors mapped to the values on a different chart with the same data.
In general if you want to investigate objects in bokeh you can use .properties_with_values()
Do you mean the palette of colors that the color mapper will use when it color maps? That's available as the .palette attribute in the mapper:
mapper.palette # these colors will be used to colormap
Or, do you mean what colors each individual rect will be assigned to? If so, that information is not available in Python. The colormapping happens in the brower, when the plot is displayed. Python never knows them.
If you need to know the colors of individual glyphs in Python, you will have to set them yourself in Python (e.g. by making a column in your CDS containing all the colors you want).

Plotly Multi Column Horizontal Legend

I am trying to create horizontal bar chart in in R using the plotly package. Due to the length of the legend items I would like for them to show horizontally at the top or bottom of the visual in 2 columns. Is it possible to dictate the number of columns for the legend?
I've been able to place the legend below the x axis successfully using Layout(legend = list(orientation='h')) however regardless of where I put the legend (using the x and y arguments) it is always just one long list. I've seen a github project for creating a multi column legend in js but not r.
Thanks,
This is not possible in a normal way. I think it has its own logic that determines how many place there it is and how many columns it will display then.
So I guess if you make your plot width smaller you could reach the goal that it will just display 2 column.
Also you can try to play around with the margin attribute (https://plot.ly/r/reference/#layout-margin) by setting r and l to 10 e.g.
An other idea could be to make the font-size in legend (https://plot.ly/r/reference/#layout-legend-font-size) bigger, so that it just uses two columns. Hope it helps.
I read the same github page and I thought that it is not possible, but seems to be! I only checked in Python, but I hope this will help in your endeavors in R as well as everyone in Python looking for information. Sadly, there is not a lot of information on Plotly here compared to other packages.
This solved my problem
Setting orientation='h' is not enough. You also have to put the legend items in different legendgroups, if you want them in different columns. Here is an example with legend labels:
fig = go.Figure([
go.Scatter(x=best_neurons_df['Test Size'],
y=best_neurons_df['Training Accuracy Max'],
# You can write anything as the group name, as long as it's different.
legendgroup="group2",
name='Training',
mode='markers',
go.Scatter(x=best_neurons_df['Test Size'],
y=best_neurons_df['Validation Accuracy Max'],
# You can write anything as the group name, as long as it's different.
legendgroup="group1",
layout=dict(title='Best Model Dependency on Validation Split',
xaxis=dict(title='Validation Set proportion'),
yaxis=dict(title='Accuracy'),
margin=dict(b=100, t=100, l=0, r=0),
legend=dict(x=1, y=1.01,xanchor='right', yanchor='bottom',
title='',
orientation='h', # Remember this as well.
bordercolor='black',
borderwidth=1
))
Example image

Manipulate Labels in Gadfly Charting Julia

I have a line chart in Gadfly using the label = "string vector" option. My question is how can I manipulate the location and size of the labels printed on the chart? I want to adjust the location of the printed labels upward slightly and increase the font size. How can I do this?
From the Gadfly documentation, I think it should be an option within 'Theme', but I can't seem to figure this out.
http://gadflyjl.org/themes.html
Thank you
As mentioned by #jfish003 there is a named argument in Theme, major_label_font_size which can be set as needed. The font size of minor label can also be set. Note that the argument is of type Measure, a simple example,
julia>plot(x=rand(10), y=rand(10), Theme(major_label_font_size=15pt))

accessing shape attribute for points when making NVD3 scatterChart with nplot/rCharts

How do you set the shape attribute for points when building a scatterChart with nplot from rCharts? Point size can be set by providing a column in the input dataframe named "size" but if there's a corresponding "shape" column consisting of strings such as "square" or "cross" the resulting graph still has the default circle points. New to R and NVD3 so I apologize for my lack of vocabulary.
It appears the newest version of nvd3 no longer works the same way as the old version. See for example. The screenshot shows shapes, and the data has shape:, but only circles are rendered in the actual chart. Also, the tests do not produce anything other than circles. I glanced at the source, and I could not find where or how to set shape. If you know how to do with nvd3, I could easily translate into a rCharts example.
I don't have a reputation of 50, but I'd like to comment.
Line 18 in this NVD3 example(Novus.github) shows how it's currently done. Likewise, all you need to do with the live code(nvd3.org) is uncomment the 'size' line in the data tab.
I attempted making a column in my df named 'shape', and using n1 <- nPlot(x~y, data=df, shape='shape', type='scatterChart'); n1$chart(onlyCircles=FALSE); and a number of other combinations. I've only spent the last two days working with rCharts but have made some exciting progress. I'm giving up on this but found it curious that these two examples weren't mentioned here, so I thought I'd mention them.
I know this question is a bit "ancient" but I faced the same problem and it took me a while to find out how to change the shapes.
I followed the approach in this example for changing the size:
nvd3 scatterPlot with rCharts in R: Vary size of points?
Here my solution:
library(rCharts)
df=data.frame(x=rep(0:2,3),y=c(rep(1,3),rep(2,3),rep(3,3)),
group=c(rep("a",3),rep("b",3),rep("c",3)),shape=rep("square",9))
p <- nPlot(y~x , group = 'group',data = df, type = 'scatterChart')
#In order to make it more pleasant to look at
p$chart(xDomain=c(-0.5,2.5))
p$chart(yDomain=c(0,4))
p$chart(sizeRange = c(200,200))
#here the magic
p$chart(scatter.onlyCircles = FALSE)
p$chart(shape = '#! function(d){return d.shape} !#')
p

Resources