Today in ChatGPT: Can you help me transition from Matplotlib to Plotly?

Solution for people who don’t want to read the docs?

Kent
4 min readFeb 6, 2023
Screenshot from the Seaborn example gallery

I have a love-hate relationship with the Matplotlib library and derivatives built on top of it like Seaborn. It is simple to use but stupidly complex to master. If you have the patience to put in the effort, it has the potential to produce pretty stunning charts, but the default settings produces underwhelming visuals. I’m stuck with it because I’ve invested so much time and energy, and I just don’t have the extra time to dive into alternative plotting APIs. One plotting library I have been considering is Plotly because it lets you make interactive charts, which Matplotlib can’t do easily. The problem is, all the tutorials and documentation start you out from scratch. I want to learn Plotly in the context of my knowledge of Matplotlib, and that’s where I think ChatGPT can help.

Spoiler alert: It didn’t go as expected

If ChatGPT is so good at understanding intent and turning it into code, and deciphering code to write documentation, maybe it can give me a personalized lesson to learn Plotly given my knowledge of Matplotlib.

Teach me Y in terms of X

I wanted ChatGPT to teach how to make charts in Plotly and compare it to making the same chart but using Matplotlib. I also expected ChatGPT to compare and contrast high-level concepts (for example the `Figure` object) and small practical details (different keywords to customize the same thing) between the two APIs.

Okay not bad. ChatGPT pointed me toward using plotly.express instead of the more low-level plotly . However, Matplotlib is a relatively low-level library and comparing these two isn’t right. Let’s ask it to compare Plotly to Seaborn, high-level plotting library built on top of Matplotlib, instead. Here’s its response.

The code for both Plotly and Seaborn are roughly equivalent but the way ChatGPT described the similarities and differences wasn’t what I wanted. I was hoping for a comparison between the way to code between the two, not a general comparison.

ChatGPT struggles in comparative reasoning

Let’s try again. This time I asked ChatGPT to compare the experience of making a histogram. I specifically requested it avoid general comparisons and limit only to the current example codes.

And here‘s how it answered me

This time it correctly avoided general similarities and differences and focused on the current example, just as I requested. However, it is still not the response I wanted. I expected something like this

To make a histogram in Plotly, use px.histogram while in Seaborn use sns.histplot

To specific bins in Plotly, use the keyword nbins while in Seaborn, use the keyword bins

ChatGPT decides to gaslight me

Let’s try one last time. This time I will give even more specific instructions to ChatGPT to try to coerce it to give me this kind of answer.

Finally, ChatGPT made comparisons between Plotly and Seaborn APIs. However, here we see the danger of simply taking ChatGPT at its word. In the Differences section, ChatGPT incorrectly asserts

Plotly provides the option to specify the number of bins in the histogram through the nbins parameter, while Seaborn does not provide a direct equivalent.

This is a pretty interest mistake because just in the previous example it gave, it uses bins in the Seaborn example. While ChatGPT appears to recall what it produced earlier, in this particular case it doesn’t remember and even claims the opposite.

Overall, this was not as successful as I expected. While ChatGPT certainly helps with learning various programming languages and APIs, it seems to struggle with “teach me Y in terms of X” prompts. It’s unclear whether this particular scenario, teaching Plotly in the context of Matplotlib/Seaborn knowledge, was the issue or if this type of request challenging for ChatGPT in general. If anyone has had different experiences with this type of request, I’d be interested in hearing about it in the comments. For now, it looks like diving into the documentation is still the only option.

Stay tuned for more Today in ChatGPT…

Previously on Today in ChatGPT

--

--

Kent

Python, finance, science, technology and life of a computational biologist