1. 程式人生 > 實用技巧 >Windows平臺Python指定版本安裝模組包

Windows平臺Python指定版本安裝模組包

此文轉載自:https://blog.csdn.net/weixin_44108388/article/details/110205949

Draw Gradient Color Map using python

github原始碼地址:
歡迎關注我!
pratical_skills_tools
Draw Gradient Color Map

Dependencies

  1. pandas
  2. matplotlib
  3. numpy
  4. seaborn

You can configure it using pip install XXX in terminal.

Results

figure1:

figure2:

Using and Explanation

1.改變顏色的種類

在程式path_Results.py檔案中,修改plot_results_path函式中的:

lc = gd.colorline(x, y, z, cmap=plt.get_cmap('cool'), linewidth=linewidth_car)  # 'jet' #'cool'

中的cmap=plt.get_cmap('cool')引數即可。可以設定的有:
參考
matplotlib tutorials中的colors部分

舉例:






2.改變圖例的標註範圍

可以進行圖例colorbar刻度的調整,包括平移和比例放縮:
在程式path_Results.py

檔案中,plot_gd_bar函式中的:

def plot_gd_bar(fig, ax, lc, max_pro, max_tran=0, cars_num=1, car_num=0, offset=0):

引數:
max_pro: 調整比例
max_tran: 調整偏移量
比如main.py中函式呼叫的時候:

cb = paths.plot_gd_bar(fig, ax, lc, result0[-1, 2], 10)
 #最後兩個引數一個是調整比例,一個是調整偏移量

比例放縮的含義:原本[0,5]可以調整為[0,10],在上面函式呼叫中的result0[-1, 2]處寫上2即可;
平移的含義:原本[0,5]可以調整為[2,7],在上面函式呼叫中的10

處寫上2即可。
具體效果可以看figure2和figure3的對比,偏移了10個單位。

Steps:

1.load CSV files

result0 = pd.read_csv("mp_1.csv")
result1 = pd.read_csv("mp_2.csv")
result0 = result0.values
result1 = result1.values

the file:
first row: x data
second row: y data
third row: z data, which is to set the gradient color map.

2.set the size of map and the limits of x axis and y axis

#設定畫布
width_img = 5
height_img = 5
fig = plt.figure(figsize=(int(width_img)+2, int(height_img)+2),
             facecolor='none')
ax = plt.gca()
#設定影象上下界
plt.xlim(0,20)
plt.ylim(0,20)  

3.draw color map

lc = paths.plot_results_path(result0,4)
lc2 = paths.plot_results_path(result1, 4)

4.draw colorbar

可以進行圖例colorbar刻度的調整,包括平移和比例放縮:
比例放縮的含義:原本[0,5]可以調整為[0,10],在下面函式呼叫中的result0[-1, 2]處寫上2即可;
平移的含義:原本[0,5]可以調整為[2,7],在下面函式呼叫中的10處寫上2即可;

cb = paths.plot_gd_bar(fig, ax, lc, result0[-1, 2], 10)
 #最後兩個引數一個是調整比例,一個是調整偏移量

Notice:
plot_gd_bar(fig, ax, lc, result0[-1, 2], 10)
#最後兩個引數一個是調整比例,一個是調整偏移量

Notice:
以上方便修改和調整的是main.pypath_Result.pygradient.py最好不要修改。