Home > Back-end >  Python Not Saving Polar Bar Chart
Python Not Saving Polar Bar Chart

Time:06-10

I've been trying to export a plot so that I can use it in a presentation and for whatever reason, python is only exporting a white square. I can save the plot using Spyder's built in Plot tab, but I'd like to use code later on to manipulate it further. Spyder has no problem saving the picture as it should be. This is what the image should look like. I have looked at people having similar issues and none of the solutions I have found are working. Sorry in advance for the long lists, they come from a text file I cannot share and I needed to share the plot info so you can see what I'm dealing with.

    import matplotlib.pyplot as plt
    import numpy as np

    r = [500, 2195, 6374, 7622, 8708, 10300, 12000, 17062, 48210, 500, 2195, 6374,
     7622, 8708, 10300, 12000, 17062, 48210, 500, 2195, 6374, 7622, 8708,
     10300, 12000, 17062, 48210, 500, 2195, 6374, 7622, 8708, 10300, 12000,
     17062, 48210, 500, 2195, 6374, 7622, 8708, 10300, 12000, 17062, 48210,
     500, 2195, 6374, 7622, 8708, 10300, 12000, 17062, 48210, 500, 2195, 6374,
     7622, 8708, 10300, 12000, 17062, 48210, 500, 2195, 6374, 7622, 8708,
     10300, 12000, 17062, 48210, 500, 2195, 6374, 7622, 8708, 10300, 12000,
     17062, 48210, 500, 2195, 6374, 7622, 8708, 10300, 12000, 17062, 48210,
     500, 2195, 6374, 7622, 8708, 10300, 12000, 17062, 48210, 500, 2195, 6374,
     7622, 8708, 10300, 12000, 17062, 48210, 500, 2195, 6374, 7622, 8708,
     10300, 12000, 17062, 48210, 500, 2195, 6374, 7622, 8708, 10300, 12000,
     17062, 48210, 500, 2195, 6374, 7622, 8708, 10300, 12000, 17062, 48210,
     500, 2195, 6374, 7622, 8708, 10300, 12000, 17062, 48210]

theta = [1.5707963267948966, 1.5707963267948966, 1.5707963267948966,
         1.5707963267948966, 1.5707963267948966, 1.5707963267948966,
         1.5707963267948966, 1.5707963267948966, 1.5707963267948966,
         1.1780972450961724, 1.1780972450961724, 1.1780972450961724,
         1.1780972450961724, 1.1780972450961724, 1.1780972450961724,
         1.1780972450961724, 1.1780972450961724, 1.1780972450961724,
         0.7853981633974483, 0.7853981633974483, 0.7853981633974483,
         0.7853981633974483, 0.7853981633974483, 0.7853981633974483,
         0.7853981633974483, 0.7853981633974483, 0.7853981633974483,
         0.39269908169872414, 0.39269908169872414, 0.39269908169872414,
         0.39269908169872414, 0.39269908169872414, 0.39269908169872414,
         0.39269908169872414, 0.39269908169872414, 0.39269908169872414,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 5.890486225480862, 5.890486225480862,
         5.890486225480862, 5.890486225480862, 5.890486225480862,
         5.890486225480862, 5.890486225480862, 5.890486225480862,
         5.890486225480862, 5.497787143782138, 5.497787143782138,
         5.497787143782138, 5.497787143782138, 5.497787143782138,
         5.497787143782138, 5.497787143782138, 5.497787143782138,
         5.497787143782138, 5.105088062083414, 5.105088062083414,
         5.105088062083414, 5.105088062083414, 5.105088062083414,
         5.105088062083414, 5.105088062083414, 5.105088062083414,
         5.105088062083414, 4.71238898038469, 4.71238898038469,
         4.71238898038469, 4.71238898038469, 4.71238898038469,
         4.71238898038469, 4.71238898038469, 4.71238898038469,
         4.71238898038469, 4.319689898685965, 4.319689898685965,
         4.319689898685965, 4.319689898685965, 4.319689898685965,
         4.319689898685965, 4.319689898685965, 4.319689898685965,
         4.319689898685965, 3.9269908169872414, 3.9269908169872414,
         3.9269908169872414, 3.9269908169872414, 3.9269908169872414,
         3.9269908169872414, 3.9269908169872414, 3.9269908169872414,
         3.9269908169872414, 3.5342917352885173, 3.5342917352885173,
         3.5342917352885173, 3.5342917352885173, 3.5342917352885173,
         3.5342917352885173, 3.5342917352885173, 3.5342917352885173,
         3.5342917352885173, 3.141592653589793, 3.141592653589793,
         3.141592653589793, 3.141592653589793, 3.141592653589793,
         3.141592653589793, 3.141592653589793, 3.141592653589793,
         3.141592653589793, 2.748893571891069, 2.748893571891069,
         2.748893571891069, 2.748893571891069, 2.748893571891069,
         2.748893571891069, 2.748893571891069, 2.748893571891069,
         2.748893571891069, 2.356194490192345, 2.356194490192345,
         2.356194490192345, 2.356194490192345, 2.356194490192345,
         2.356194490192345, 2.356194490192345, 2.356194490192345,
         2.356194490192345, 1.9634954084936207, 1.9634954084936207,
         1.9634954084936207, 1.9634954084936207, 1.9634954084936207,
         1.9634954084936207, 1.9634954084936207, 1.9634954084936207,
         1.9634954084936207]

dist_dict = {500: 0, 2195: 500, 6374: 2195, 7622: 6374, 8708: 7622,
             10300: 8708, 12000: 10300, 17062: 12000, 48210: 17062}

color = [[0.4337593822888133, 1, 0, 0.5], [0, 1, 0.3589234543485882, 0.5],
         [0, 1, 0.8732349039106471, 0.5], [0, 1, 0.950744292378161, 0.5],
         [0, 0.987542480132762, 1, 0.5], [0, 0.9105326234228976, 1, 0.5],
         [0, 0.8486243615317225, 1, 0.5], [0, 0.7065353470072946, 1, 0.5],
         [0, 0.2881460605850948, 1, 0.5], [0.24467076265135201, 1, 0, 0.5],
         [0, 1, 0.5520373881065379, 0.5], [0, 0.9345411986441171, 1, 0.5],
         [0, 0.8561417738638891, 1, 0.5], [0, 0.7992651938940958, 1, 0.5],
         [0, 0.7183087259776617, 1, 0.5], [0, 0.654421569718946, 1, 0.5],
         [0, 0.5134214132493449, 1, 0.5], [0, 0.10661126076259698, 1, 0.5],
         [0.14315279896261757, 1, 0, 0.5], [0, 1, 0.6570024312441916, 0.5],
         [0, 0.8166006266245653, 1, 0.5], [0, 0.7406008868771122, 1, 0.5],
         [0, 0.6815654227479401, 1, 0.5], [0, 0.6086875140738033, 1, 0.5],
         [0, 0.5349442580597802, 1, 0.5], [0, 0.402153983720543, 1, 0.5],
         [0, 0.0, 1, 0.5], [0.20792745942162982, 1, 0, 0.5],
         [0, 1, 0.5873911232658962, 0.5], [0, 0.8977978954143955, 1, 0.5],
         [0, 0.8166006266245653, 1, 0.5], [0, 0.7614057624040139, 1, 0.5],
         [0, 0.6815654227479401, 1, 0.5], [0, 0.6246888427781467, 1, 0.5],
         [0, 0.4903028743408392, 1, 0.5], [0, 0.08095646791643404, 1, 0.5],
         [0.3000997413414246, 1, 0, 0.5], [0, 1, 0.5007818163553039, 0.5],
         [0, 0.9725656433705228, 1, 0.5], [0, 0.8912301261778117, 1, 0.5],
         [0, 0.8249199867402587, 1, 0.5], [0, 0.7511767307262356, 1, 0.5],
         [0, 0.6943001507564422, 1, 0.5], [0, 0.5550775347998512, 1, 0.5],
         [0, 0.1523453164077397, 1, 0.5], [0.42415993208808533, 1, 0, 0.5],
         [0, 1, 0.3589234543485882, 0.5], [0, 1, 0.8732349039106471, 0.5],
         [0, 1, 0.9547696064986495, 0.5], [0, 0.987542480132762, 1, 0.5],
         [0, 0.9105326234228976, 1, 0.5], [0, 0.8486243615317225, 1, 0.5],
         [0, 0.7065353470072946, 1, 0.5], [0, 0.3102799878945453, 1, 0.5],
         [0.5931152749854753, 1, 0, 0.5], [0, 1, 0.1912797777816162, 0.5],
         [0, 1, 0.6898704359927648, 0.5], [0, 1, 0.7682698607729934, 0.5],
         [0, 1, 0.8435021769698476, 0.5], [0, 1, 0.90610290865922, 0.5],
         [0, 1, 0.9671669007089791, 0.5], [0, 0.8977978954143955, 1, 0.5],
         [0, 0.4903028743408392, 1, 0.5], [0.66834759118233, 1, 0, 0.5],
         [0, 1, 0.09804959796319213, 0.5], [0, 1, 0.5873911232658962, 0.5],
         [0, 1, 0.6570024312441916, 0.5], [0, 1, 0.726613739222487, 0.5],
         [0, 1, 0.791388399681499, 0.5], [0, 1, 0.8435021769698476, 0.5],
         [0, 1, 0.9800773299420615, 0.5], [0, 0.6399093011974337, 1, 0.5],
         [0.7289160191628308, 1, 0, 0.5], [0, 1, 0.04996113479533171, 0.5],
         [0, 1, 0.5202855116183245, 0.5], [0, 1, 0.6001258512743981, 0.5],
         [0, 1, 0.6570024312441916, 0.5], [0, 1, 0.726613739222487, 0.5],
         [0, 1, 0.791388399681499, 0.5], [0, 1, 0.9095885037592779, 0.5],
         [0, 0.7183087259776617, 1, 0.5], [0.7948354791304184, 1, 0, 0.5],
         [0.028438289984896503, 1, 0, 0.5], [0, 1, 0.4567712872820795, 0.5],
         [0, 1, 0.5305145432961027, 0.5], [0, 1, 0.5873911232658962, 0.5],
         [0, 1, 0.6570024312441916, 0.5], [0, 1, 0.7077014327924926, 0.5],
         [0, 1, 0.8435021769698476, 0.5], [0, 0.7902223138963012, 1, 0.5],
         [0.8732349039106468, 1, 0, 0.5], [0.11818287470326316, 1, 0, 0.5],
         [0, 1, 0.37115865059944064, 0.5], [0, 1, 0.44866803906695485, 0.5],
         [0, 1, 0.5007818163553039, 0.5], [0, 1, 0.5751559270150437, 0.5],
         [0, 1, 0.6272697043033921, 0.5], [0, 1, 0.746747015962558, 0.5],
         [0, 0.8776646186743244, 1, 0.5], [0.7796150207111321, 1, 0, 0.5],
         [0.010607293185169286, 1, 0, 0.5], [0, 1, 0.46509064739777295, 0.5],
         [0, 1, 0.541090387145226, 0.5], [0, 1, 0.6001258512743981, 0.5],
         [0, 1, 0.673003759948535, 0.5], [0, 1, 0.726613739222487, 0.5],
         [0, 1, 0.8435021769698476, 0.5], [0, 0.7809094576670342, 1, 0.5],
         [0.7467470159625584, 1, 0, 0.5], [0, 1, 0.02843828998489628, 0.5],
         [0, 1, 0.5103812665560317, 0.5], [0, 1, 0.5873911232658962, 0.5],
         [0, 1, 0.6417819728249046, 0.5], [0, 1, 0.7077014327924926, 0.5],
         [0, 1, 0.7682698607729934, 0.5], [0, 1, 0.8958738769814425, 0.5],
         [0, 0.7296538859158003, 1, 0.5], [0.7100037127328362, 1, 0, 0.5],
         [0, 1, 0.07307967370383728, 0.5], [0, 1, 0.5633825480446766, 0.5],
         [0, 1, 0.6417819728249046, 0.5], [0, 1, 0.6898704359927648, 0.5],
         [0, 1, 0.7682698607729934, 0.5], [0, 1, 0.8163583239408536, 0.5],
         [0, 1, 0.9547696064986495, 0.5], [0, 0.6682886311521451, 1, 0.5],
         [0.7100037127328362, 1, 0, 0.5], [0, 1, 0.07307967370383728, 0.5],
         [0, 1, 0.5633825480446766, 0.5], [0, 1, 0.6417819728249046, 0.5],
         [0, 1, 0.6898704359927648, 0.5], [0, 1, 0.7682698607729934, 0.5],
         [0, 1, 0.8163583239408536, 0.5], [0, 1, 0.9588475405932859, 0.5],
         [0, 0.654421569718946, 1, 0.5], [0.6452290522738244, 1, 0, 0.5],
         [0, 1, 0.15492617793298513, 0.5], [0, 1, 0.6417819728249046, 0.5],
         [0, 1, 0.726613739222487, 0.5], [0, 1, 0.791388399681499, 0.5],
         [0, 1, 0.8732349039106471, 0.5], [0, 1, 0.9202852379474438, 0.5],
         [0, 0.9345411986441171, 1, 0.5], [0, 0.5349442580597802, 1, 0.5]]

fig = plt.figure(dpi=250, figsize=[10,10])
ax = fig.add_axes([1, 1, 1, 1], polar=True)
for i in range(len(r)):
    ax.bar(theta[i], (r[i]-dist_dict[r[i]]), width=np.pi/8,
           bottom=dist_dict[r[i]], color=color[i], edgecolor=None)
plt.ylim(0, max(r))
plt.savefig("name")

CodePudding user response:

fig.add_axes first argument is rect, where

rect: sequence of float
The dimensions [left, bottom, width, height] of the new Axes. All quantities are in fractions of figure width and height.

So, you need to change that line to, for example,

ax = fig.add_axes([0, 0, 1, 1], polar=True)

Source

  • Related