Inserting Upward Triangle In Mathtext String Matplotlib - matplotlib

I am using the function plt.text in Matplotlib to produce text within my plot. In addition, I am using Mathtext to bold a portion of the text string, as seen in this piece of code:
plt.text(0.01,0.32,fill(r"$\bf{Peaks:}$"+appended_text,57), ha='left',va="top", multialignment="left", fontsize=10.5, wrap=True)
Within my plot, I am currently denoting specific points with an filled upward triangle ("^" via plt.plot in Matplotlib), and would like to use this filled upward triangle symbol within the Mathtext bolded string above.
My initial approach was to try: r"$\bf{Peaks\ [^]:}$", however this simply moved the closed portion of the bracket as an exponential symbol.
Is there a way to replicate this filled triangle within Mathtext?
How would I use

Related

Dots repel in Pandas scatterplot

I am trying to draw a scatterplot where visualizing all the dots hue and size is important.
However, some dots are localized at the same location x,y therefore they overlap, and we cannot see them well.
I know there is the equivalent of the 'repel' function in Pandas for the dots labels with the following script.
https://github.com/Phlya/adjustText
Would anyone know if there is another software that allow to repel the dots themselves, and not just the text annotation?

Halcon - Extract straight edge from XLD

I have a XLD edge, like the one in red in the sample picture below.
I need to extract start/endpoint of straight lines that reppresent it. Hough lines sort of work for this, but the results are not really replicable. minor changes in the contour produce unexpected results.
How can the contours be extracted as straight lines? (blue) with start and finish coordinates?
lines shorter than a specified length should not be counted as separate line.
Contour needs to be converted to a polygon using the following function:
gen_polygons_xld (Object, Polygons, 'ramer', 25.0)
The only adjustable parameter is the alpha (25.0) which decides the approximation threshold.

How can I get and set the position of a draggable legend in matplotlib

I'm trying to get and set the position of a draggable legend in matplotlib. My application consists of an interactive GUI, which has a redraw/plot function that should perform the follow steps:
save the position of the current legend.
clear the current axes and perform various plotting operations, which may or may add labels to their plots.
build a new draggable legend (ax.legend().draggable()) and restore the old position of the legend.
In between these steps the user is free to drag the legend around, and the goal is to persist the legend position when the plots are redrawn.
My first approach was to use oldpos = legend.get_bbox_to_anchor() and legend.set_bbox_to_anchor(oldpos) in steps 1 and 3. However this causes to move the legend completely off the visible area.
Note that I have to use ax.legend() and cannot use fig.legend(lines, labels), since step 2 is completely decoupled, i.e., I don't know anything about lines and labels in step 3. According to answers to the question How to position and align a matplotlib figure legend? there seems to be a difference between these two possibilities regarding axes or figure coordinates. Obviously my problem calls for figure coordinates, but I haven't fully understood how to convert the bbox to a "bbox in figure coordinates".
The even more severe problem I just realized is that apparently legend.get_bbox_to_anchor() always seems to return the same values irrespective of the drag position. So maybe the anchor can only be (ab-)used to manipulate the position of static legends? Is there another/proper way to save and restore the position of a draggable legend?
By looking at the implementation of Legend I found out that there is an undocumented property _loc, which exactly does what I want. My solution now looks astonishingly simple:
oldLegPos = ax.get_legend()._loc
# perform all plotting operations...
legend = ax.legend().draggable()
legend._loc = oldLegPos
It looks like _loc automatically stores figure coordinates, since I do not have to convert the coordinates in any way (eg. when the plotting operations completely change the axes ranges/coordinates).

Core Plot - adding a vertical/horizontal line indicator on a selected value point

I am using core plot to make a line graph for my iPhone app. So far I successfully made the line graph from my xml data.
Furthermore I added a text layer that shows the value (for example 40) once I select the cell
holding the value 40. For this, I use the function:
(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
So now I want to have a vertical line on the graph to indicate the selected value (the 40). I tried adding CPTBarplot but somehow the bars show only at the beginning of the graph axis.
Is there a function from core plot like the above that will create a line indicator?
I would appreciate if someone can give me some hint how to solve this problem and thank you very much in advance.
You could use a scatter plot for that. There's a point selection demo in the Mac CPTTestApp that draws a crosshair over the selected point. It would be trivial to modify that to only draw the vertical line.
The -numberOfRecordsForPlot: datasource method returns the number of points in the selection indicator (5 for the crosshairs) or zero (0) if there is no current selection. The -numberForPlot:field:recordIndex: method returns the points in the indicator. The points are drawn in this order:
Left
Right
Center (with plot symbol)
Top
Bottom
The -symbolForScatterPlot:recordIndex: method controls the plot symbol in the center. You can eliminate this method if you don't need any symbols on the indicator plot.

Positioning figure and table in figure

I'm trying to put both a plot and a table in a figure, but I want some whitespace to separate the two. How do I position the table/plot at arbitrary positions? What I have now is the table of values showing up IMMEDIATELY under the x-axis (so that it's actually colliding into my axis labels...)
I don't know matplotlib at all...The documentation is not written very well either...
To position something in a figure you have to use the function set_position([left, bottom, width, height]). Example:
matplotlib.pyplot.axes().set_position([0.15, 0.20, 0.80, 0.70])