This might be related to tick spacing but I am not sure how to set it to display all the x-axis values. I want to have all the x-axis legends to be displayed in the graph. Ta.allocate_text(fig,ax,np.hstack(x_lines),np.While plotting using scatterplot in matplotlib, I find some of the values from x-axis are missing in the labels. Text_lists = for _ in range(4)]įor x_line,y_line,text_list in zip(x_lines,y_lines,text_lists):Īx.plot(x_line,y_line,color="black",linewidth=0.5) With a few parameter tweaks you can generate a plot like this in a fraction of a second: import textalloc as ta The following example shows how you might use it in this case. Just created a package for problems like this: textalloc The more complicated graph is now, still a bit iffy but much better! Text_plotter(text, eucs, covers, text_positions, txt_width, txt_height) Text_positions = get_text_positions(text, eucs, covers, txt_width, txt_height) Head_width=txt_width, head_length=txt_height*0.5, Text_positions = sorted_ltp + txt_heightĭef text_plotter(text, x_data, y_data, text_positions, txt_width,txt_height):įor z,x,y,t in zip(text, x_data, y_data, text_positions): Local_text_positions = > (y - txt_height)Īnd (abs(i - x) txt_height * 2: #if True then room to fit a word inĪ = (sorted_ltp + txt_height, a) import sysĭef get_text_positions(text, x_data, y_data, txt_width, txt_height): ![]() If someone knows, please post an improvement (or add a comment with the method). I don't however know how to find the exact width and height of the text. Again credit for the original solution goes to the answer for Matplotlib overlapping annotations. With a lot of fiddling, I figured it out. Here is the example image: import matplotlib.pyplot as pltĪdjust_text(texts, only_move=, force_points=0.15,Īrrowprops=dict(arrowstyle="->", color='r', lw=0.5)) ![]() I just wanted to post here another solution, a small library I wrote to implement this kind of things: Īn example of the process can be seen here: Images (if this works) can be found here (this code): ![]() P1 = plt.plot(eucs,covers,color="black", alpha=0.5) Plt.ylabel("Percentage Timewindows Attended") Plt.xlabel("Proportional Euclidean Distance") ![]() I'm having trouble converting the "axis" methods over to what I want to do, and I don't understand how the text lines up. The method suggested in the accepted answer to Matplotlib overlapping annotations looks extremely promising, however is for bar graphs. I'm trying to stop annotation text overlapping in my graphs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |