Chart Not Drawing

Posted on
Sat Oct 10, 2020 7:48 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Chart Not Drawing

Hey Dave

You had been a big help awhile ago while I was trying to get a Bar Chart to work. We.... You ended up with some python code to manually write the CVS files for my project, and those files were used to draw the bar chart.

I'm now trying to do a new bar chart, so have re-used the same python code as before to create the CVS files. As far as I can tell, the CVS files are being written correctly. I've opened both the new files and some of the still-in-use older ones with Numbers, and the fields look exactly the same.

But for some reason, the new bar chart png isn't being drawn, and I get this error code:
Code: Select all
 Matplotlib Warning              [C-Rain Bar] zero-size array to reduction operation minimum which has no identity. See plugin log for more information.
   Matplotlib Debug                [C-Server Temp & Humidity] [C-Server Temp & Humidity] X axis label is suppressed to make room for the chart legend.
.

The X-Axis debug comes up with several charts so don't think that it is the problem. No doubtI've got something wrong somewhere, but if you could just point me in the right direction of were to look, I'm guessing I can track down my error.

Posted on
Sun Oct 11, 2020 5:29 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Chart Not Drawing

The second line isn't an error -- all that's saying is that you have filled the X-Axis label field and also asked for a chart legend to be plotted. Given the nature of the plots, the plugin can't do both and is not plotting the axis label (and letting you know why). The first one is trying to tell us what the problem is, and we need to examine the plugin log for more information. Take a look at the file located at (adjust the Indigo version number for your situation if needed):

Code: Select all
/Library/Application Support/Perceptive Automation/Indigo 7.4/Logs/com.fogbert.indigoplugin.matplotlib/
and post the complete error message. Also, please post the script you're using to generate the data for the new chart.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Oct 11, 2020 11:47 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Chart Not Drawing

I'm attaching the log, and here is the script for writing the CVS files:
Code: Select all
rain = indigo.variables[1938961]

inches = "{:.3f}".format(float(rain.value) *.03937) #coverts mm to inches

indigo.variable.updateValue(1852577407, inches) #updates inches variable

csv_path = '/Users/bradford/MatPlotLib/'  # put your CSV Engine data path here
values = {
    'RainToday': ('1970-01-01 00:00:00.000000,', indigo.variables[1852577407].value),  # change these variable ids to match yours
    'RainYesterday': ('1970-01-02 00:00:00.000000,', indigo.variables[35080668].value),
    'RainThisWeek': ('1970-01-03 00:00:00.000000,', indigo.variables[986779847].value),
    'RainThisMonth': ('1970-01-04 00:00:00.000000,', indigo.variables[1385001124].value),
   'RainLastMonth': ('1970-01-05 00:00:00.000000,', indigo.variables[1169660509].value),
   }

for key in values.keys():

    with open(csv_path + key + ".csv", 'w') as outfile:
        outfile.write("Timestamp," + key + "\n")
        outfile.write(values[key][0] + values[key][1])


just a note that in Indigo, the "Rain Last Month line in Indigo is perfectly aligned with the lines above... no extraneous spaces, just tabs. And this is exactly as the last set of scripts you helped me with on another bar graph project.

And here is the log while manually re-drawing all charts:

Code: Select all
Oct 11, 2020 at 12:33:12 PM
   Matplotlib                      [Battery Chart] Chart updated successfully.
   Matplotlib                      [C-24 Hour Polar Wind] Chart updated successfully.
   Matplotlib Debug                [C-24 Hour Rain] [C-24 Hour Rain] X axis label is suppressed to make room for the chart legend.
   Matplotlib                      [C-24 Hour Rain] Chart updated successfully.
   Matplotlib Debug                [C-24 Hour wind Line] [C-24 Hour wind Line] X axis label is suppressed to make room for the chart legend.
   Matplotlib                      [C-24 Hour wind Line] Chart updated successfully.
   Matplotlib Debug                [C-48 Temp & Humidity] [C-48 Temp & Humidity] X axis label is suppressed to make room for the chart legend.
   Matplotlib                      [C-48 Temp & Humidity] Chart updated successfully.
   Matplotlib Debug                [C-AC Cycle Bar Chart] [C-AC Cycle Bar Chart] X axis label is suppressed to make room for the chart legend.
   Matplotlib                      [C-AC Cycle Bar Chart] Chart updated successfully.
   Matplotlib Debug                [C-AC Times Bar Chart] [C-AC Times Bar Chart] X axis label is suppressed to make room for the chart legend.
   Matplotlib                      [C-AC Times Bar Chart] Chart updated successfully.
   Matplotlib Warning              [C-Rain Bar] zero-size array to reduction operation minimum which has no identity. See plugin log for more information.
   Matplotlib Debug                [C-Server Temp & Humidity] [C-Server Temp & Humidity] X axis label is suppressed to make room for the chart legend.
   Matplotlib                      [C-Server Temp & Humidity] Chart updated successfully.
   Matplotlib                      [Ran LineB] Chart updated successfully.
   Matplotlib                      ==================== Redraw Charts Now Menu Action Complete ====================



Thanking you in advance for your help.
Attachments
plugin.log
(262.11 KiB) Downloaded 157 times
plugin.log.2020-10-10.txt
(401.94 KiB) Downloaded 161 times

Posted on
Sun Oct 11, 2020 12:31 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Chart Not Drawing

The critical bit from the log is this:

Code: Select all
2020-10-10 23:52:51.510   CRITICAL     Plugin.pluginErrorHandler           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TRACEBACK !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2020-10-10 23:52:51.511   CRITICAL     Plugin.pluginErrorHandler           !!! Traceback (most recent call last):
2020-10-10 23:52:51.511   CRITICAL     Plugin.pluginErrorHandler           !!!   File "plugin.py", line 3451, in chart_bar
2020-10-10 23:52:51.512   CRITICAL     Plugin.pluginErrorHandler           !!!     width = np.min(np.diff(p_dict['x_obs{0}'.format(thing)])) * 0.8
2020-10-10 23:52:51.512   CRITICAL     Plugin.pluginErrorHandler           !!!   File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/fromnumeric.py", line 2214, in amin
2020-10-10 23:52:51.513   CRITICAL     Plugin.pluginErrorHandler           !!!     out=out, keepdims=keepdims)
2020-10-10 23:52:51.514   CRITICAL     Plugin.pluginErrorHandler           !!!   File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/_methods.py", line 21, in _amin
2020-10-10 23:52:51.515   CRITICAL     Plugin.pluginErrorHandler           !!!     out=out, keepdims=keepdims)
2020-10-10 23:52:51.515   CRITICAL     Plugin.pluginErrorHandler           !!! ValueError: zero-size array to reduction operation minimum which has no identity
2020-10-10 23:52:51.515   CRITICAL     Plugin.pluginErrorHandler           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
or more specifically, this bit:

Code: Select all
width = np.min(np.diff(p_dict['x_obs{0}'.format(thing)])) * 0.8
that line of code should only be reached if you have the bar width set to 0 (zero). With that setting, the plugin tries to judge how wide to set the bars by itself based on the dates in the CSV data. So it could be that something about the dates in your data file isn't quite right and causing the plugin to get confused.

Can you attach the CSV file to this thread as a text file? Also, please ensure that there is a valid value in the bar width field (zero should be among the valid options).

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Oct 11, 2020 5:27 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Chart Not Drawing

Hey Dave

Of course you were exactly right I had mostly left the plugin settings for the graph as they were, and am 99% sure I had exactly the same issue last time I tried to work with bar graphs, but just didn't go back to those posts to check. I've got it working now, and sorry for mostly wasting your time.

Cheers

Posted on
Sun Oct 11, 2020 6:51 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Chart Not Drawing

That's great news. Thanks for letting me know.

I've included some additional safety around that setting thanks to your question (which will be included in the next release).

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Oct 12, 2020 9:07 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Chart Not Drawing

and if I may offer just a tiny suggestion... my current bar graph project is measuring rain fall. Sometimes there is a lot... most of the time, there isn't any at all. When the CVS values are 0, the bar disappears as there is no data to display. So sometimes my 4 bar graph has only 3 or 2 or 1 bars, and when that happens, they take up the available space. The "3 of 4" is what happens now when one of the data fields is "0", but the 4 of 4 is what I think would make more sense.


Cheers
Attachments
4 of 4 bars.png
4 of 4 bars.png (69.8 KiB) Viewed 3701 times
3of 4 bars.png
3of 4 bars.png (68.74 KiB) Viewed 3701 times

Posted on
Mon Oct 12, 2020 4:54 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Chart Not Drawing

I understand completely what you're looking for. I'll have to dig into the code to see what's going on, but I doubt that I purposefully removed the bar for zero values (can't swear to that at the moment, though). Depending on your circumstance, you may be able to "trick" the chart by changing the zero value to something super tiny (like 0.0001) in the CSV data--but that's a kludge for sure.

I'll see what I can do.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Oct 12, 2020 5:35 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Chart Not Drawing

you may be able to "trick" the chart by changing the zero value to something super tiny

Already done!

Posted on
Tue Oct 13, 2020 7:27 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Chart Not Drawing

Had some time to do a little research on this. Apparently, it's a matplotlib "feature". Consider this:

Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3]
y = [0, 4, 6]

plt.bar(x,y)
plt.show()
This simple plot yields:
figure_1.png
figure_1.png (7.66 KiB) Viewed 3640 times

In order to force spots for all values, we can force the x axis to show them:

Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3]
y = [0, 4, 6]

plt.bar(x,y)
plt.xlim([x[0], len(x)+1])
plt.show()
Thus:
figure_2.png
figure_2.png (7.9 KiB) Viewed 3640 times

I would suspect that this is a matter of taste and it would likely be better as an option. I will look to add an additional setting so we can elect to force them to show.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Oct 13, 2020 8:32 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Chart Not Drawing

I agree that for some people in some situations, the option would be a good idea. This would probably be ideal but also seems like a lot more work for you.

Posted on
Tue Oct 13, 2020 9:20 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Chart Not Drawing

Not that much work honestly. The "hard" part is to not break existing stuff. :D

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Oct 13, 2020 12:10 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Chart Not Drawing

Understood

I know nothing about coding, but please let me know if there is any other way I can help you in this process.

Posted on
Tue Oct 13, 2020 2:45 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Chart Not Drawing

Thanks for the offer, but I should be good from here.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Fri Oct 23, 2020 10:35 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Chart Not Drawing

So this is a little weird.


I manually changed the CVS files for Bar #2 and Bar #3 to 0, and when the chart redrew, I still have spacing for all 4 bars....

Who is online

Users browsing this forum: No registered users and 2 guests