Search code examples
pandasmatrixplotlabelscatter-matrix

How to fix overly long axis label in Pandas Scatter_matrix?


Pandas scatter_matrix

This is the part of Pandas scatter_matrix.

Why the only one label (0.60000000....) is so long? How can I fix it?

This is part of my code:

from pandas.plotting import scatter_matrix

attributes = ["Chance of Admit ", "CGPA", "GRE Score", "TOEFL Score"]
scatter_matrix(admission[attributes], figsize=(12, 8))

Solution

  • The label (0.6000000000000001) almost exactly in the middle of the labels (0.8) and (0.4) is due to the effects of rounding due to the usage of floating point variables and the formatting of these numerical data types.

    Most decimal values, including those that lie in tenths cannot be expressed in binary, but floating point variables use binary in pandas. Therefore, some decimal values could deviate by a factor of 10-15 and still show up in the floating point variables written in the default format.

    To fix this issue, consider formatting the labels of the axis, such that the floats are rounded to the nearest tenth of hundredth. Consider the display.float_format option: try set_option('float_format', #YOUR FORMAT#) or set_eng_float_format(accuracy=3, use_eng_prefix=True).

    Source: Options and Settings from official documentation