[matplotlib-devel] Re : displaying ticklabels on a graph

2011-05-01 Thread naga coulibaly
See enclosed the python file of my code.
The code is not a professional one because i just start python and matplotlib.

Thanks,

Naga





De : John Hunter 
À : Clyng11 
Cc : matplotlib-devel@lists.sourceforge.net
Envoyé le : Sam 30 avril 2011, 22h 45min 22s
Objet : Re: [matplotlib-devel] displaying ticklabels on a graph

On Wed, Apr 27, 2011 at 4:17 AM, Clyng11  wrote:
>
> I run this code, but labels do not appear under the ticks.
>
>  # label the X ticks with years
>  self.mpl.canvas.ax.set_xticks(np.arange(len(years))+width/2,
> [int(year) for year in years])
>  self.mpl.canvas.ax.set_xticklabels([str(year) for year in years])
>
> I Need an help.


Could you post a complete, free-standing example that we can run that
exposes your problem?
# used to parse files more easily
from __future__ import with_statement
# Numpy module
import numpy as np
# matplotlib colormap module
import matplotlib.cm as cm
# Matplotlib font manager
import matplotlib.font_manager as font_manager
#need for navigation tool bar 
#from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar

# for command-line arguments
import sys, os

# Qt4 bindings for core Qt functionalities (non-GUI)
from PyQt4 import QtCore
# Python Qt4 bindings for GUI objects
from PyQt4 import QtGui
#from PyQt4.QtGui import QAction, QIcon
from qgis.core import *
# import the MainWindow widget from the converted .ui files
from mplmainwindow import Ui_MplMainWindow

# Initialize Qt resources from file resources.py
import resources

class DoGraphCsv (QtGui.QDialog, Ui_MplMainWindow):

   def __init__(self, iface):
  QtGui.QDialog.__init__( self )
  self.iface = iface
  self.setupUi( self )

   def initGui(self):
  # Create action that will start plugin configuration
  self.action = QtGui.QAction(QtGui.QIcon(":/plugins/graphcsvfile/csv_graph.png"), \
	"Csv graph...", self.iface.mainWindow())
#  self.action = QAction( QCoreApplication.translate( "mnuCsvGraph", "Csv graph", self.iface.mainWindow() )
#  self.action.setIcon(QIcon(":/plugins/graphcsvfile/csv_graph.png"))
# self.calcStats.setIcon( QIcon( ":/statist.png" ) )
  self.action.setWhatsThis( "Csv file graphic" )
  # connect the action to the run method
  QtCore.QObject.connect(self.action, QtCore.SIGNAL("triggered()"), self.run)
   
  # Add toolbar button and menu item
  self.iface.addToolBarIcon(self.action)
  self.iface.addPluginToMenu("&Csv graph...", self.action)


   def unload(self):
  # Remove the plugin menu item and icon
  self.iface.removePluginMenu("&Csv graph...",self.action)
  self.iface.removeToolBarIcon(self.action)

# run method that performs all the real work
   def run(self):
  # create and show the dialog
  self.dlg = Ui_MplMainWindow()
  # connect the signals with the slots
  QtCore.QObject.connect(self.mplactionAdd, QtCore.SIGNAL("clicked()"), self.select_file)
  QtCore.QObject.connect(self.mplpushButton, QtCore.SIGNAL("clicked()"), self.validate_entries)

  # show the dialog
  self.show()
  result = self.exec_()

   def select_file(self):
  """opens a file select dialog"""
  # open the dialog and get the selected file
  file = QtGui.QFileDialog.getOpenFileName()
  # if a file is selected
  if file:
 # update the lineEdit text with the selected filename
 self.mpllineEdit.setText(file)

   def validate_entries(self):

  # check to see that all fields have been entered
  msg = ''

  if self.mpllineEdit.text() == '' or \
 self.xlabelEdit.text() == '' or \
 self.ylabelEdit.text() == '' or \
 self.titleEdit.text() == '':
# ui.lineEdit_min_version_no.text() == '' or \
# ui.lineEdit_menu_text.text() == '' or \
# ui.lineEdit_company_name.text() == '' or \
# ui.lineEdit_email_address.text() == '':
  msg = 'All fields are required to create a graph\n'
# try:
#flt = float(str(ui.lineEdit_version_no.text()))
#flt = float(str(ui.lineEdit_min_version_no.text()))
# except:
# msg += 'Version numbers must be numeric'
# if msg != '':
  QtGui.QMessageBox.warning(self, "Missing Information", msg)

  else:
 self.plot_csvfile()

   def plot_csvfile(self):

  width = .6
  # open CSV file
  with open(self.mpllineEdit.text()) as f:

 # read the first line, splitting the years
 years = map(int, f.readline().split(',')[1:])

 # we prepare the dtype for exacting data; it's made of:
 # <1 string field> 
 dtype = [('continents', 'S16')] + [('', np.int32)]*len(years)

 # we load the file, setting the delimiter and the dtype above
 y = np.loadtxt(f, delimiter=',', dtype=dtype)
   
 # "map" the resulting structure to be easily accessible:
 # the first column (made of str

[matplotlib-devel] Re : displaying ticklabels on a graph

2011-05-01 Thread naga coulibaly
Also enclosed the csv file I use. I work with Qt4 and Quantum GIS.

Thanks,

Naga





De : John Hunter 
À : Clyng11 
Cc : matplotlib-devel@lists.sourceforge.net
Envoyé le : Sam 30 avril 2011, 22h 45min 22s
Objet : Re: [matplotlib-devel] displaying ticklabels on a graph

On Wed, Apr 27, 2011 at 4:17 AM, Clyng11  wrote:
>
> I run this code, but labels do not appear under the ticks.
>
>  # label the X ticks with years
>  self.mpl.canvas.ax.set_xticks(np.arange(len(years))+width/2,
> [int(year) for year in years])
>  self.mpl.canvas.ax.set_xticklabels([str(year) for year in years])
>
> I Need an help.


Could you post a complete, free-standing example that we can run that
exposes your problem?
Continent,1950,1975,2000,2010,2025,2050
Africa,227270,418765,819462,1033043,1400184,1998466
Asia,1402887,2379374,3698296,4166741,4772523,5231485
Europe,547460,676207,726568,732759,729264,691048
Latin America,167307,323323,521228,588649,669533,729184
Northern America,171615,242360,318654,351659,397522,448464
Oceania,12807,21286,31160,35838,42507,51338
--
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel