Python pptx custom color for each category
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm looking at example here:
https://python-pptx.readthedocs.org/en/latest/user/charts.html?highlight=color#pie-chart
chart_data = ChartData()
chart_data.categories = ['West', 'East', 'North', 'South', 'Other']
chart_data.add_series('Series 1', (0.135, 0.324, 0.180, 0.235, 0.126))
chart = slide.shapes.add_chart(
XL_CHART_TYPE.PIE, x, y, cx, cy, chart_data
).chart
chart.has_legend = True
chart.legend.position = XL_LEGEND_POSITION.BOTTOM
chart.legend.include_in_layout = False
chart.plots[0].has_data_labels = True
data_labels = chart.plots[0].data_labels
data_labels.number_format = '0%'
data_labels.position = XL_LABEL_POSITION.OUTSIDE_END
But I can't understand how to make each category with custom not automatic color:
west is yellow, east is blue, north is grey, south is red, other as brown for example.
python python-pptx
add a comment |
I'm looking at example here:
https://python-pptx.readthedocs.org/en/latest/user/charts.html?highlight=color#pie-chart
chart_data = ChartData()
chart_data.categories = ['West', 'East', 'North', 'South', 'Other']
chart_data.add_series('Series 1', (0.135, 0.324, 0.180, 0.235, 0.126))
chart = slide.shapes.add_chart(
XL_CHART_TYPE.PIE, x, y, cx, cy, chart_data
).chart
chart.has_legend = True
chart.legend.position = XL_LEGEND_POSITION.BOTTOM
chart.legend.include_in_layout = False
chart.plots[0].has_data_labels = True
data_labels = chart.plots[0].data_labels
data_labels.number_format = '0%'
data_labels.position = XL_LABEL_POSITION.OUTSIDE_END
But I can't understand how to make each category with custom not automatic color:
west is yellow, east is blue, north is grey, south is red, other as brown for example.
python python-pptx
Have you read this section in the documentation?
– scanny
Feb 24 '16 at 2:27
add a comment |
I'm looking at example here:
https://python-pptx.readthedocs.org/en/latest/user/charts.html?highlight=color#pie-chart
chart_data = ChartData()
chart_data.categories = ['West', 'East', 'North', 'South', 'Other']
chart_data.add_series('Series 1', (0.135, 0.324, 0.180, 0.235, 0.126))
chart = slide.shapes.add_chart(
XL_CHART_TYPE.PIE, x, y, cx, cy, chart_data
).chart
chart.has_legend = True
chart.legend.position = XL_LEGEND_POSITION.BOTTOM
chart.legend.include_in_layout = False
chart.plots[0].has_data_labels = True
data_labels = chart.plots[0].data_labels
data_labels.number_format = '0%'
data_labels.position = XL_LABEL_POSITION.OUTSIDE_END
But I can't understand how to make each category with custom not automatic color:
west is yellow, east is blue, north is grey, south is red, other as brown for example.
python python-pptx
I'm looking at example here:
https://python-pptx.readthedocs.org/en/latest/user/charts.html?highlight=color#pie-chart
chart_data = ChartData()
chart_data.categories = ['West', 'East', 'North', 'South', 'Other']
chart_data.add_series('Series 1', (0.135, 0.324, 0.180, 0.235, 0.126))
chart = slide.shapes.add_chart(
XL_CHART_TYPE.PIE, x, y, cx, cy, chart_data
).chart
chart.has_legend = True
chart.legend.position = XL_LEGEND_POSITION.BOTTOM
chart.legend.include_in_layout = False
chart.plots[0].has_data_labels = True
data_labels = chart.plots[0].data_labels
data_labels.number_format = '0%'
data_labels.position = XL_LABEL_POSITION.OUTSIDE_END
But I can't understand how to make each category with custom not automatic color:
west is yellow, east is blue, north is grey, south is red, other as brown for example.
python python-pptx
python python-pptx
edited Dec 14 '15 at 10:49
sevatster
asked Dec 14 '15 at 10:29


sevatstersevatster
2619
2619
Have you read this section in the documentation?
– scanny
Feb 24 '16 at 2:27
add a comment |
Have you read this section in the documentation?
– scanny
Feb 24 '16 at 2:27
Have you read this section in the documentation?
– scanny
Feb 24 '16 at 2:27
Have you read this section in the documentation?
– scanny
Feb 24 '16 at 2:27
add a comment |
3 Answers
3
active
oldest
votes
Custom coloring on a series is accomplished using the .fill
attribute on the series.
Unfortunately that attribute hasn't been implemented yet for pie charts, only for bar and column charts.
http://python-pptx.readthedocs.org/en/latest/api/chart.html#barseries-objects
It is possible to change the default coloring though, in the "template" .pptx file you start with, which accomplishes the same thing for many folks. All the charts in the file will have the same coloring, but it doesn't have to be the built-in defaults.
Thanks. I have seen this issue for pie chart.
– sevatster
Feb 25 '16 at 7:42
Can you show how to use .fill attribute?
– idazuwaika
Aug 5 '16 at 17:05
Some examples at python-pptx.readthedocs.io/en/latest/user/autoshapes.html#fill. API documentation at: python-pptx.readthedocs.io/en/latest/api/…
– scanny
Aug 5 '16 at 17:10
thanks... funny i didn't find it when googling earlier
– idazuwaika
Aug 6 '16 at 9:29
add a comment |
I've responded to this question on Github, it is now possible to modify pie charts colors.
As the pie chart is only one serie of multiple points, you'll need to modify every point individually. This can be done by itering through each points of the first Serie (as it's the only one you have in a pie chart) and changing the color with whatever you like. The point color is in the .format.fill argument, that you can interact with easily using the links scanny provided above.
Here is a simple snippet for your use case:
# [yellow, blue, grey, red, brown]
color_list = ["ffff00", "0000ff", "D3D3D3", "ff0000", "A52A2A"]
# Go through every point of the first serie and modify the color
for idx, point in enumerate(chart.series[0].points):
col_idx = idx % len(color_list)
point.format.fill.solid()
point.format.fill.fore_color.rgb = RGBColor.from_string(color_list[col_idx])
Cheers !
add a comment |
It is possible to change the color of the line in a line chart because I tried many suggestions without success like this code:
_green = RGBColor(156, 213, 91)
plot = chart.plots[0]
series = plot.series[0]
line = series.format.line
line.fill.rgb = _green
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34264715%2fpython-pptx-custom-color-for-each-category%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Custom coloring on a series is accomplished using the .fill
attribute on the series.
Unfortunately that attribute hasn't been implemented yet for pie charts, only for bar and column charts.
http://python-pptx.readthedocs.org/en/latest/api/chart.html#barseries-objects
It is possible to change the default coloring though, in the "template" .pptx file you start with, which accomplishes the same thing for many folks. All the charts in the file will have the same coloring, but it doesn't have to be the built-in defaults.
Thanks. I have seen this issue for pie chart.
– sevatster
Feb 25 '16 at 7:42
Can you show how to use .fill attribute?
– idazuwaika
Aug 5 '16 at 17:05
Some examples at python-pptx.readthedocs.io/en/latest/user/autoshapes.html#fill. API documentation at: python-pptx.readthedocs.io/en/latest/api/…
– scanny
Aug 5 '16 at 17:10
thanks... funny i didn't find it when googling earlier
– idazuwaika
Aug 6 '16 at 9:29
add a comment |
Custom coloring on a series is accomplished using the .fill
attribute on the series.
Unfortunately that attribute hasn't been implemented yet for pie charts, only for bar and column charts.
http://python-pptx.readthedocs.org/en/latest/api/chart.html#barseries-objects
It is possible to change the default coloring though, in the "template" .pptx file you start with, which accomplishes the same thing for many folks. All the charts in the file will have the same coloring, but it doesn't have to be the built-in defaults.
Thanks. I have seen this issue for pie chart.
– sevatster
Feb 25 '16 at 7:42
Can you show how to use .fill attribute?
– idazuwaika
Aug 5 '16 at 17:05
Some examples at python-pptx.readthedocs.io/en/latest/user/autoshapes.html#fill. API documentation at: python-pptx.readthedocs.io/en/latest/api/…
– scanny
Aug 5 '16 at 17:10
thanks... funny i didn't find it when googling earlier
– idazuwaika
Aug 6 '16 at 9:29
add a comment |
Custom coloring on a series is accomplished using the .fill
attribute on the series.
Unfortunately that attribute hasn't been implemented yet for pie charts, only for bar and column charts.
http://python-pptx.readthedocs.org/en/latest/api/chart.html#barseries-objects
It is possible to change the default coloring though, in the "template" .pptx file you start with, which accomplishes the same thing for many folks. All the charts in the file will have the same coloring, but it doesn't have to be the built-in defaults.
Custom coloring on a series is accomplished using the .fill
attribute on the series.
Unfortunately that attribute hasn't been implemented yet for pie charts, only for bar and column charts.
http://python-pptx.readthedocs.org/en/latest/api/chart.html#barseries-objects
It is possible to change the default coloring though, in the "template" .pptx file you start with, which accomplishes the same thing for many folks. All the charts in the file will have the same coloring, but it doesn't have to be the built-in defaults.
answered Feb 24 '16 at 2:34
scannyscanny
10.6k12245
10.6k12245
Thanks. I have seen this issue for pie chart.
– sevatster
Feb 25 '16 at 7:42
Can you show how to use .fill attribute?
– idazuwaika
Aug 5 '16 at 17:05
Some examples at python-pptx.readthedocs.io/en/latest/user/autoshapes.html#fill. API documentation at: python-pptx.readthedocs.io/en/latest/api/…
– scanny
Aug 5 '16 at 17:10
thanks... funny i didn't find it when googling earlier
– idazuwaika
Aug 6 '16 at 9:29
add a comment |
Thanks. I have seen this issue for pie chart.
– sevatster
Feb 25 '16 at 7:42
Can you show how to use .fill attribute?
– idazuwaika
Aug 5 '16 at 17:05
Some examples at python-pptx.readthedocs.io/en/latest/user/autoshapes.html#fill. API documentation at: python-pptx.readthedocs.io/en/latest/api/…
– scanny
Aug 5 '16 at 17:10
thanks... funny i didn't find it when googling earlier
– idazuwaika
Aug 6 '16 at 9:29
Thanks. I have seen this issue for pie chart.
– sevatster
Feb 25 '16 at 7:42
Thanks. I have seen this issue for pie chart.
– sevatster
Feb 25 '16 at 7:42
Can you show how to use .fill attribute?
– idazuwaika
Aug 5 '16 at 17:05
Can you show how to use .fill attribute?
– idazuwaika
Aug 5 '16 at 17:05
Some examples at python-pptx.readthedocs.io/en/latest/user/autoshapes.html#fill. API documentation at: python-pptx.readthedocs.io/en/latest/api/…
– scanny
Aug 5 '16 at 17:10
Some examples at python-pptx.readthedocs.io/en/latest/user/autoshapes.html#fill. API documentation at: python-pptx.readthedocs.io/en/latest/api/…
– scanny
Aug 5 '16 at 17:10
thanks... funny i didn't find it when googling earlier
– idazuwaika
Aug 6 '16 at 9:29
thanks... funny i didn't find it when googling earlier
– idazuwaika
Aug 6 '16 at 9:29
add a comment |
I've responded to this question on Github, it is now possible to modify pie charts colors.
As the pie chart is only one serie of multiple points, you'll need to modify every point individually. This can be done by itering through each points of the first Serie (as it's the only one you have in a pie chart) and changing the color with whatever you like. The point color is in the .format.fill argument, that you can interact with easily using the links scanny provided above.
Here is a simple snippet for your use case:
# [yellow, blue, grey, red, brown]
color_list = ["ffff00", "0000ff", "D3D3D3", "ff0000", "A52A2A"]
# Go through every point of the first serie and modify the color
for idx, point in enumerate(chart.series[0].points):
col_idx = idx % len(color_list)
point.format.fill.solid()
point.format.fill.fore_color.rgb = RGBColor.from_string(color_list[col_idx])
Cheers !
add a comment |
I've responded to this question on Github, it is now possible to modify pie charts colors.
As the pie chart is only one serie of multiple points, you'll need to modify every point individually. This can be done by itering through each points of the first Serie (as it's the only one you have in a pie chart) and changing the color with whatever you like. The point color is in the .format.fill argument, that you can interact with easily using the links scanny provided above.
Here is a simple snippet for your use case:
# [yellow, blue, grey, red, brown]
color_list = ["ffff00", "0000ff", "D3D3D3", "ff0000", "A52A2A"]
# Go through every point of the first serie and modify the color
for idx, point in enumerate(chart.series[0].points):
col_idx = idx % len(color_list)
point.format.fill.solid()
point.format.fill.fore_color.rgb = RGBColor.from_string(color_list[col_idx])
Cheers !
add a comment |
I've responded to this question on Github, it is now possible to modify pie charts colors.
As the pie chart is only one serie of multiple points, you'll need to modify every point individually. This can be done by itering through each points of the first Serie (as it's the only one you have in a pie chart) and changing the color with whatever you like. The point color is in the .format.fill argument, that you can interact with easily using the links scanny provided above.
Here is a simple snippet for your use case:
# [yellow, blue, grey, red, brown]
color_list = ["ffff00", "0000ff", "D3D3D3", "ff0000", "A52A2A"]
# Go through every point of the first serie and modify the color
for idx, point in enumerate(chart.series[0].points):
col_idx = idx % len(color_list)
point.format.fill.solid()
point.format.fill.fore_color.rgb = RGBColor.from_string(color_list[col_idx])
Cheers !
I've responded to this question on Github, it is now possible to modify pie charts colors.
As the pie chart is only one serie of multiple points, you'll need to modify every point individually. This can be done by itering through each points of the first Serie (as it's the only one you have in a pie chart) and changing the color with whatever you like. The point color is in the .format.fill argument, that you can interact with easily using the links scanny provided above.
Here is a simple snippet for your use case:
# [yellow, blue, grey, red, brown]
color_list = ["ffff00", "0000ff", "D3D3D3", "ff0000", "A52A2A"]
# Go through every point of the first serie and modify the color
for idx, point in enumerate(chart.series[0].points):
col_idx = idx % len(color_list)
point.format.fill.solid()
point.format.fill.fore_color.rgb = RGBColor.from_string(color_list[col_idx])
Cheers !
answered Mar 1 at 15:29
Milo ParigiMilo Parigi
214
214
add a comment |
add a comment |
It is possible to change the color of the line in a line chart because I tried many suggestions without success like this code:
_green = RGBColor(156, 213, 91)
plot = chart.plots[0]
series = plot.series[0]
line = series.format.line
line.fill.rgb = _green
add a comment |
It is possible to change the color of the line in a line chart because I tried many suggestions without success like this code:
_green = RGBColor(156, 213, 91)
plot = chart.plots[0]
series = plot.series[0]
line = series.format.line
line.fill.rgb = _green
add a comment |
It is possible to change the color of the line in a line chart because I tried many suggestions without success like this code:
_green = RGBColor(156, 213, 91)
plot = chart.plots[0]
series = plot.series[0]
line = series.format.line
line.fill.rgb = _green
It is possible to change the color of the line in a line chart because I tried many suggestions without success like this code:
_green = RGBColor(156, 213, 91)
plot = chart.plots[0]
series = plot.series[0]
line = series.format.line
line.fill.rgb = _green
answered Jan 3 at 11:00


asmatrkasmatrk
324
324
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34264715%2fpython-pptx-custom-color-for-each-category%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you read this section in the documentation?
– scanny
Feb 24 '16 at 2:27