plotting multiple plots with string for x label

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

plotting multiple plots with string for x label

Jason Snyder

I am trying to plot multiple plots where for the labels of the x axis I use strings.  I the below script in which I am attempting to do this.


       data = np.loadtxt(sys.argv[1], dtype='str',delimiter=',', skiprows=1,  usecols=(0,1,2,3,4,5))
       x = data[:,0]
       date = data[:,1]
       value1 = data[:,2]
       value2 = data[:,3]

       my_xticks = data[:,1]
       plt.xticks(x.astype(float), my_xticks)

       fig, (ax1,ax2) = plt.subplots(nrows=2)
       my_xticks = data[:,1]
       ax1.set_xticks(x.astype(float), my_xticks)   
       ax1=plt.plot(x, value1)
       plt.tick_params(axis='both',which='major', labelsize=7)
       plt.title('Value1',fontsize=10)
       plt.grid()

      ax2=plt.plot(x, value2)
      plt.tick_params(axis='both',which='major', labelsize=7)
      plt.title('Value2',fontsize=10)
      plt.grid()

What can I do to tweak this program to get desired results?


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: plotting multiple plots with string for x label

Paul Hobson-2
It's going to be really hard to know what your desired output is without a runnable script. Rather than reading from a file that only you have, it's better to hardcode some representative values for your arrays.

It looks like your trying to plot a time series. Matplotlib handles that pretty well without having to resort to using strings:



On Tue, Jan 24, 2017 at 5:11 PM, Jason Snyder <[hidden email]> wrote:

I am trying to plot multiple plots where for the labels of the x axis I use strings.  I the below script in which I am attempting to do this.


       data = np.loadtxt(sys.argv[1], dtype='str',delimiter=',', skiprows=1,  usecols=(0,1,2,3,4,5))
       x = data[:,0]
       date = data[:,1]
       value1 = data[:,2]
       value2 = data[:,3]

       my_xticks = data[:,1]
       plt.xticks(x.astype(float), my_xticks)

       fig, (ax1,ax2) = plt.subplots(nrows=2)
       my_xticks = data[:,1]
       ax1.set_xticks(x.astype(float), my_xticks)   
       ax1=plt.plot(x, value1)
       plt.tick_params(axis='both',which='major', labelsize=7)
       plt.title('Value1',fontsize=10)
       plt.grid()

      ax2=plt.plot(x, value2)
      plt.tick_params(axis='both',which='major', labelsize=7)
      plt.title('Value2',fontsize=10)
      plt.grid()

What can I do to tweak this program to get desired results?


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users