I am working on a fuzzy control example, which uses the skfuzzy library. Its visualization module is built on top of Matplotlib.
Usually, after constructing a fuzzy variable, with the necessary membership function (either using an auto constructor, giving it the number of linguistic variables to be used - 3, 5 or 7,or supplying a custom list of linguistic variables), the .view() method can be called, which returns a plot of the membership function. That plot uses whatever is the default cmap.
This is usually fine, but in my case I'm building an example with temperature control, and the it would have been really nice, if for the membership functions' plot I could use a colour gradient from blue (cold) to red (warm) to represent the various temperature (qualitative) variables. Thus, I want to change the cmap to 'bwr'.
So I need to somehow address the figure or axes of the plot and give it a new cmap. After some digging in the skfuzzy library I found the FuzzyVariableVisualizer class which contains the .view() method and so instead of directly using the .view() on the skfuzzy.control.antecedent_consequent.Antecedent object I have created (which uses a .view().show() and thus does not give access to the underlying figure and axis), I first passed the .Antecedent to the FuzzyVariableVisualizer() and then used its .view() method, which does return the figure and the axes.
But now, I have no idea how to set new cmap for it. Unfortunately google searches yielded only one similar result (this), but it wasn't useful to me. And Matplotlib is a bit too complex for me to dig around (and it will just take too much time).
Here is some code to reproduce the state I'm at. Does anyone have an elegant way to address this?
import numpy as np
import matplotlib.pyplot as plt
import skfuzzy as fuzz
from skfuzzy import control as ctrl
from skfuzzy.control import visualization
room_temp = ctrl.Antecedent(np.arange(0, 11, 1), 'room temperature')
clothing = ctrl.Antecedent(np.arange(0, 11, 1), 'amount of clothing')
temp_control = ctrl.Consequent(np.arange(0, 11, 1), 'temperature control')
temp_qualitative_values = ['absolute zero',
'freezing',
'extremely cold',
'cold',
'chilly',
'OK',
'warm',
'hot',
'very hot',
'hot as hell',
'melting']
clothing.automf(3)
clothing.view()
temp_control.automf(5)
temp_control.view()
# I want to chage the cmap of the following figure
room_temp.automf(10, names=temp_qualitative_values)
room_temp_viz = visualization.FuzzyVariableVisualizer(room_temp)
fig, ax = room_temp_viz.view()
plt.show()
I've tried (and did not work):
plt.set_cmap('bwr')
plt.show()