Xlsxwriter Excel Chart Custom Data Label Position - python

I am drawing an excel scatter chart with python and xlsx writer and use custom data labels for one series. But I can not set the position of the custom labels like I can with the default labels. If I set the position of the custom labels they dont change in the chart. In the debugger or if I check their label options in excel itself I can see the changed position values, but they are not applied in the drawing.
At default the custom labels seem to bet set at right. I want them on top but I cant get this. The code is like that:
chart.add_series( .., 'data_labels': {'custom': my_custom_labels, 'position': 'above'})
But the changes wont appy to the chart.
I also found i can set the default label position (label_position_default) in the chart object (which is right on default) but it wont change the custom label position either.
Anyone has an idea how to get a custom data label on top position?

Related

Folium - Label each area in a GeoJSON

I have a GeoJSON file that contains country/empire borders in the year 1800. I am trying to depict this using Folium. I would like to have the name of each country/empire to be displayed (text) within each country/empire region in the map (basically the same as what is shown on "normal" present-day maps, but I can't just overlay this over present-day maps because the borders have changed over time). The GeoJSON file has a field that contains the name of each respective country/border, but I don't know how to display this on the map.
I do not want this to be a tooltip / popup. Instead, I want the text displayed in the base map, viewable without hovering your mouse over the map or clicking on anything.
I have seen some similar questions, and the responses are essentially to use a DivIcon. But this seems like a clunky solution and not very clean when dealing with a large map and many, many labels.
Is there a good way to display this? I looked in the Folium documentation and didn't see any arguments in the GeoJson class that seems like it would do this. (For example, it would be nice to tell Folium to automatically add 'region' labels, and to use a given field as the source of the labels).
Thanks!

Xlsxwriter hide data series in scatter plot

I have used xlsxwriter to add various different data series (lines) to a plot. What I would like to do now is disable certain series by default but, still have the disabled series available to reenable when looking at the graph.
For example, in the following image, while xlsxwriter adds all the series as I want it to, I would also like to not show "Sample2" & "Sample3" while showing "Sample1" by default.
The only feature I have been able to find that does something similar would be the:
# Delete/hide series index 0 and 2 from the legend.
chart.set_legend({'delete_series': [0, 2]})
It appears to "delete" it more than hide it because if I try to toggle them back on they don't show up.
Maybe it's not possible through xlsxwriter but is there any other way I can implement this functionality?
I hope you're enjoying your stay here lmao.
Delete/hide series index 0 and 2 from the legend.
chart.set_legend({'delete_series': [0, 2]})
This work?
If not...
for Mac:
Click on the chart.
On the ribbon, click Chart Design and then click Select Data.
On the Chart Design tab, click Select Data
This selects the data range of the chart and displays the Select Data Source dialog box.
To edit a legend series, in the Legend entries (series) box, click the series you want to change. Then, edit the Name and Y values boxes to make any changes.
To rearrange a legend series, in the Legend entries (series) box, click the series you want to change and then select the alternate text or alternate text arrows.
Windows:
Right-click your chart, and then choose Select Data.
n the Legend Entries (Series) box, click the series you want to change.
Click Edit, make your changes, and click OK.
Changes you make may break links to the source data on the worksheet.
To rearrange a series, select it, and then click Move Up alternate text or Move Down alternate text.
You can also add a data series or remove them in this dialog box by clicking Add or Remove. Removing a data series deletes it from the chart—you can’t use chart filters to show it again.
If you want to rename a data series, see Rename a data series.
I hope this is helpful to you.

How to delete a plot from chart space in pptx python?

I'd like to delete plot that is in the chart space. Does any one know how to do that with pptx python? Since there's option to delete plots in powerpoint GUI. Is there any way I can do that with python pptx?
I have four charts in a slide and I want to first store the shapes of plots and then delete the plots inside of the charts.
Reading the docs I found this paragraph that shows in more detail how plots work:
A plot is like a sub-chart, containing one or more series and drawn as
a particular chart type, like column or line. This distinction is
needed for charts that combine more than one type, like a line chart
appearing on top of a column chart. A chart like this would have two
plot objects, one for the series appearing as columns and the other
for the lines. Most charts only have a single plot and python-pptx
doesn’t yet support creating multi-plot charts, but you can access
multiple plots on a chart that already has them.
From your question I assume that you want to delete the plot to replace it with a new one. I suggest that you delete the series inside the existing plot and add to it the new series you need.

Add Label Annotations on Axes

I currently annotate my charts with the last value of each series by adding a Label and supplying my the name of corresponding range it's plotted on:
Label(
...
x=data.index.max(),
y=data.loc[data.index.max(), 'my_col'],
y_range_name='my_range'
...
)
Which gives me:
How do I move the labels so they are positioned on their respective axis?
Example:
Please note that my labels' y-positioning is off, so I need some help with that aspect too. I've tried tweaking the y_offset but this has not yielded any consistently good results.
My data are always numerical time series.
As of Bokeh 1.2 there is no built-in annotation or glyph that will display outside the central plot area. There is an open issue on GitHub that this is similar to that you can follow or comment on. For the time being, something like this would require making a custom extension

How do you get the range of the x-axis of a Plotly graph?

I'm trying to retrieve the range of the x-axis when you zoom in a plotly scatter plot, but when I tried to access it using:
figure['layout']['xaxis']['range']
it just returns 'None'.
This is the code that I am using to create the graph:
# self.plot contains the dataframe passed to the function to be plotted
self.plot = df
# Creates the plotly plot figure
self.fig = self.plot.iplot(asFigure=True,kind='scatter', xTitle='Date', yTitle='Temperature')
# Displays the plot
iplot(self.fig, show_link=False)
I'm using cufflinks to create the plot from a pandas DataFrame so I don't explicitly set the layout.xaxis.range to anything. Also I'm using a Jupyter Notebook to display the graph, if that helps at all. So is there any way of getting the range of the x-axis of the current view window of the plot? Thanks in advance!
That does not seem to be possible at the moment using python. There's a post on community.plot.ly that says:
Graph parameters don’t dynamically change with chart actions. However,
as you zoom, the plot does emit data regarding the new x-axis range,
you’re unable to to access this information directly in Python.
Instead you’d have to use javascript:
https://plot.ly/javascript/zoom-events/

Categories