Plotting
  • 16 Oct 2021
  • 1 Minute to read
  • Dark
    Light

Plotting

  • Dark
    Light

Article summary

Pandas uses MatPlotLib to do its visualization but simplifies many common issues found with MatPlotLib. In most cases, Pandas meets graphing needs. However, if deep customizations are needed, it is necessary to use MatPlotLib. See pandas.pydata.org or matplotlib.org for more detailed information on Pandas plotting.

The query and table below are used for reference points on all graphs displayed in this document.

Query:

dataframe = get_hits('()diabetes', store='Records', limit=5, fields='extract.patient_id, extract.age,  extract.patient_full_name, extract.weight_standard')
print(dataframe)

Response:


extract.ageextract.patient_full_nameextract.patient_idextract.weight_standard
043Gail Hill94451170.0
143Gail Hill94451170.0
236Rhoda Sweet92830220.5
313Jescie Lyons92721138.0
470Lyle Cash92750257.0

Displaying Graphs

Note:
The ability to print and view graphs has been wrapped in a function. Use output_plot() to print graphs.

The information in this document is valid but intended for more advanced users. Using output_plot() along with the axis object (also called ax) is less complicated.

The primary function of Pandas is .plot().

dataframe.plot()


In this state, the graph is not very useful. By defining an x and y axis, it is possible to specify the information that appears on the table and on which axis.

dataframe.plot(x='extract.age', y='extract.weight_standard')


It is possible to choose which type of graph to display when using the kind parameter. Some common types of graphs are bar, line, scatter, barh and hist.

dataframe.plot(x='extract.age', y='extract.weight_standard', kind='scatter')


from pandas.tools.plotting import scatter_matrix
scatter_matrix(dataframe)



Was this article helpful?