Python Forum
how to include characters in a diagram with matplotlib - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: how to include characters in a diagram with matplotlib (/thread-12956.html)



how to include characters in a diagram with matplotlib - atlass218 - Sep-20-2018

Hello;
I created an application with which if I click on the button "save", there is creation of a text file in which I save data in columns. among these data there is the date in first colone
here is the contents of the file (file.txt):



01/12/2010 ... 0.132
02/05/2011 ... 0.186
28/12/2011 ... 0.168
04/06/2012 ... 0.122
29/12/2012 ... 0.144
06/06/2013 ... 0.112
07/01/2014 ... 0.186
08/06/2014 ... 0.168
19/12/2014 ... 0.152
10/06/2015 ... 0.164


this content is not fixed since each time you click on the save button a new line is added to the text file


import numpy as np
import matplotlib.pyplot as plt

def graphe_loc35R():
	x,y = np.loadtxt("file.txt", unpack=True)
	plt.plot(x,y,'o')
	
	plt.xlabel('date')
	plt.ylabel('ddm')
	
	plt.show()
I would like help to find out how to include characters in the x-axis of a diagram built with matpltlib

thanks


RE: how to include characters in a diagram with matplotlib - Mekire - Sep-20-2018

Quote:I would like help to find out how to include characters in the x-axis of a diagram built with matpltlib
So you want the date labels on the X-axis?
If so you are going to want the xticks function.
Something like:
plt.xticks(x_values, labels, rotation=30)



RE: how to include characters in a diagram with matplotlib - atlass218 - Sep-20-2018

hello;
but this code is for limited number of values. at my text file (file.txt), the number of line is not fixed and il will be modify each time a personn click on save button


RE: how to include characters in a diagram with matplotlib - Mekire - Sep-21-2018

It can absolutely work. Load the dates into a variable named labels anytime it changes and update your xticks.


RE: how to include characters in a diagram with matplotlib - atlass218 - Sep-24-2018

hi
I did not understand your answer
I would like you to facilitate me the task by procuring me the procedure if it is possible, since I am still a beginner with regard to the programming and especially the python language
thank you