How do you set the font size of a Chart Title with Python PPTX? - python-3.x

I add a chart with:
doughnutchart_data.add_series('YTD COMPLETION TO PLAN', (PerformancePercent, NotPerformedPercent))
This gives me a chart title with the text, but how do I change the font size?
This:
ThisDoughnutChart.title.font.size = Pt(12)
Gives me this error:
AttributeError: 'Chart' object has no attribute 'title'

It seems that creating a chart title text_frame over writes the title applied from the add_series attribute. So I tried adding a new title. This worked for me:
ThisDoughnutChart.chart_title.text_frame.text = 'YTD COMPLETION TO PLAN'
ThisDoughnutChart.chart_title.text_frame.paragraphs[0].font.size = Pt(12)

Version 0.6.11 another example
shape = slide.shapes
title_shape = shape.title
title_shape.text_frame.paragraphs[0].font.size=Pt(10)

You can set the global font size of the chart with the following:
from pptx.util import Inches, Pt
ThisDoughnutChart.font.size = Pt(10)

Related

How to add text on interactive Scatter on Altair?

I try to adapt the Selection Detail Example from altair doc (https://altair-viz.github.io/gallery/select_detail.html#selection-detail-example).
I won't detailed my Dataframe structure which is identical with the one from the example (included variable names).
The native code is working well :
# Data is prepared, now make a chart
selector = alt.selection_single(empty='all', fields=['id'])
base = alt.Chart(data).properties(
width=250,
height=250
).add_selection(selector)
points = base.mark_point(filled=True, size=200,opacity=0.9).encode(
x=alt.X('mean(y)',title='Durée de perception',scale=alt.Scale(domain=(11, 23))),
y=alt.Y('mean(x)',title='Taux de marge (%PM)'),
color=alt.condition(selector, 'id:O', alt.value('lightgray')),
tooltip = ['mean(y)','mean(x)']
)
timeseries = base.mark_bar(opacity=1).encode(
x=alt.X('time', title='Items'),
y=alt.Y('value', scale=alt.Scale(domain=(-1, 1)),stack=None),
color=alt.Color('id:O',scale=alt.Scale(domain=domain, range=range_))
#, legend=None)
).transform_filter(
selector
)
points | timeseries
No problem at this stage even if it could be useful to hide all the bars on right chart when no selection is made on the right chart (don't know if it's possible ?)
After that I try to add text to the scatter plot adding this at the end of the code :
text = points.mark_text(dy=-5).encode(
x=alt.X('mean(y)',title='Durée de perception',scale=alt.Scale(domain=(11, 23))),
y=alt.Y('mean(x)',title='NBV (%CA)'),
text='id:O'
)
(points + text) | timeseries
which leads to the following error message :
Javascript Error: Duplicate signal name: "selector094_tuple"
This usually means there's a typo in your chart specification. See the javascript console for the full traceback.
If you have any idea on how to do, i would be grateful
Thanks
The issue is that you cannot add the same selection to two different layers, which you do implicitly by deriving text from points. Try this instead:
text = alt.Chart(data).mark_text(dy=-5).encode(
x=alt.X('mean(y)',title='Durée de perception',scale=alt.Scale(domain=(11, 23))),
y=alt.Y('mean(x)',title='NBV (%CA)'),
text='id:O'
)
(points + text) | timeseries

How to set or modify the font size from a chart embedded in a userform

I'm programming an userform to show a graph with data stored in a range of cells, but when the graph shows it is so small and it gets impossible to read, and it shows another label with "series 2" even when i didn't added it.
I tried changing the properties of the image box, from "0 fmPictureSizeModeClip to fmPictureModeZoom but it only makes it blurry, i tried to modify my code adding:
MyChart.Parent.Width = 1200
MyChart.Parent.Height = 780
But it only the bars get big and the labels and title keeps small, and being unable to read.
Set MyChart = ActiveSheet.Shapes.AddChart(xlColumnClustered).Chart
MyChart.Parent.Width = 1200
MyChart.Parent.Height = 780
MyChart.SeriesCollection.NewSeries
MyChart.SeriesCollection(1).Name = ChartName
MyChart.SeriesCollection(1).Values = ChartData
MyChart.SeriesCollection(1).XValues = ActiveSheet.Range("K32:K43")
This is the userform after adding:
MyChart.Parent.Width = 1200
MyChart.Parent.Height = 780
and this is before it, as you may see the text is illegible, the name of the chart in the screenshot disappeared but i corrected the code and now it appears but just as small as the other text in the chart
If complementary info needed i will gladly provide it,
any help is appreciated.
I figured out the answer.
MyChart.Axes(xlCategory).TickLabels.Font.Size = 20
MyChart.Axes(xlValue).TickLabels.Font.Size = 20
MyChart.Legend.Font.Size = 20
MyChart.ChartTitle.Font.Size=24

word wrap data labels python-pptx

Is it possible to set word wrap to false all data labels in my chart?
I was trying to do plots[0].data_labels.format.text_frame.word_wrap = False but data_labels hasn't format property
Start with the DataLabels object. This is available on the .data_labels attribute of a plot or a series. You might want to try both to see what behavior you get:
from pptx.text.text import TextFrame
# ---obtain reference to <c:dLbls> element in question---
data_labels = plot2.data_labels
dLbls = data_labels._element
# ---use its <c:txPr> child to create TextFrame object---
text_frame = TextFrame(dLbls.get_or_add_txPr(), None)
# ---turn off word-wrap in the usual way---
text_frame.word_wrap = False
This can be made more compact, I show it step-by-step here for clarity.

Change color and legend of plotLearnerPrediction ggplot2 object

I've been producing a number of nice plots with the plotLearnerPrediction function in the mlr package for R. They look like this. From looking into the source code of the plotLearnerPrediction function it looks like the color surfaces are made with geom_tile.
A plot can for example be made by:
library(mlr)
data(iris)
#make a learner
lrn <- "classif.qda"
#make a task
my.task <- makeClassifTask(data = iris, target = "Species")
#make plot
plotLearnerPrediction(learner = lrn, task = my.task)
Now I wish to change the colors, using another red, blue and green tone to match those of some other plots that I've made for a project. for this I tried scale_fill_continuous and scale_fill_manual without any luck (Error: Discrete value supplied to continuous scale) I also wish to change the legend title and the labels for each legend entry (Which I tried giving appropriate parameters to the above scale_fill's). There's a lot of info out there on how to set the geom_tile colours when producing the plot, but I haven't found any info on how to do this post-production (i.e. in somebody else's plot object). Any help would be much appreciated.
When you look into the source code you see how the plot is generated and then you can see which scale has to be overwritten or set.
In this example it's fairly easy:
g = plotLearnerPrediction(learner = lrn, task = my.task)
library(ggplot2)
g + scale_fill_manual(values = c(setosa = "yellow", versicolor = "blue", virginica = "red"))

How to increase size of text value on top of MPAndroid Bar Chart?

I have created a chart using MPAndroid Chart. I want to know how can I increase the size of text value on top of each bar in MPAndroid Bar Chart? Which API should I use? I have circled the value in the attached picture in Red circle
you can try it by using
barDataset.setValueTextSize(12f);
where barDataset is BarDataSet
I was able to find the answer to my question after some trials. This is the code to set the font size of left and right Y-axis on a MPAndroidChart
import com.github.mikephil.charting.charts.CombinedChart;
//Code snippet
CombinedChart combinedChart = (CombinedChart) findViewById(R.id.chart);
YAxis yaLeft = combinedChart.getAxisLeft();
YAxis yaRight = combinedChart.getAxisRight();
yaLeft.setTextSize(14/*textSize*/);
yaRight.setTextSize(14/*textSize*/);

Resources